# (M3-R5) Programming and Problem Solving through Python January 2021 [Solved]

### 1. Each question below gives multiple choices of answers. Choose the most appropriate one. (1×10)

1.1 Find the output of following Python Programs.

``````a = ”Meethmeafterparty”
b = 13
print a + b
``````

(a) 29
(b) 14
(c) error in code
(d) 15

1.2 Find the output of the following Python programs.

``````class Acc:
def_init_(self, id):
self.id = id
id = 555
acc = Acc(111)
print acc.id
``````

(a) 111
(b) 555
(c) 666
(d) error in code

1.3 Which of the following is an invalid variable ?
(a)
my_string_1
(b) foo
(c) _
(d) 1st_string

1.4 Which of the following is an invalid variable ?

``````x = [‘ab’,’cd’]
for I in x:
i.upper()
print(x)
``````

(a) ab
(b) cd
(c) [‘ab’,’cd’]
(d) [‘cd’,’ab’]

1.5 What is the output of the following program ?

``````a = 2
b = ‘3.77’
c = -8
str = ‘{0:4f} {0:3d} {2} {1}’. Format (a,b,c) print(str1)
``````

(a) 2.0000 2 -8 3.77
(b) 2 3.77 -8 3.77
(c) 2.000 3 -8 3.77
(d) 2.000 2 8 3.77

1.6 Find the output of the following Python programs:

``````def gfg(x,1=[]):
for i in range(x):
1.append(i*i)
print(1)
gfg(2)
``````

(a) [3,2,1,0,1,4]
(b) [0,1]
(c) [0,1,0,1,4]
(d) error in code

1.7 Suppose t = (1,2,4,3), which of the following is incorrect ?
(a)
print (t )
(b) t  = 45
(c) print (max(t))
(d) print (Len(t))

1.8 What is the output of the following Python code?

``````>>>t1=(1,2,4,3)
>>>t2=(1,2,3,4)
>>>t1<t2
``````

(a) True
(b) False
(c) Error
(d) (1,2,4,3)

1.9 Which of the following statements is false about recursion ?
(a)
Every recursive function must have a base case
(b) Infinite recursion can occur if the base case isn’t mentioned
(c) A recursive function makes the code easier to understand
(d) Every recursive function must have a return value

1.10 What will be the output of following code ?

1=[1,2,3,4,5]
m=functools.rediuce(lambda x, y:x if x>y else y, 1)
print(m)

(a) Error
(c) 1
(d) 5

### 4) Fill in the blanks:- 1×10=10

4.1 The output of following Python program is __b___.

``````r = lambda q: q * 2
s = lambda q: q * 3
x = 2
x = r(x)
x = s(x)
x = r(x)
print x
``````

4.2 Let consider the following Python code is

``````a = True
b = False
c = False
if a or b and c:
print “TRUE”
else:
print “False”
``````

the output of this code is __l___.

4.3 Recursive functions usually take __e___ memory space than non-recursive function.

4.4 Python programing language was created by __h__.

4.5 Python support Object-Oriented style or technique of programming that encapsulates code within __j__.

4.6 __a__ Returns the current time instant, a floating-point number of seconds since the epoch.

4.7 All parameters (arguments) in the Python language are passed by __d__

4.8 The __f__ can be accessed by only inside the function in which they are declared, whereas global variables can be accessed throughout the program body by all functions.

4.9 The differences between tuples and list are, the tuples cannot be changed unlike lists and tuples use __c__ whereas list use square brackets.

4.10 Python converts numbers internally in an expression containing mixed type to a Common type for evaluation. But sometimes, coerce a number explicitly from one type to another to satisfy the requirements of __i__ parameter

### PART TWO (Answer any FOUR Questions)

Q5.
a. Write the basic steps required by the interpreter to execute a python program.
b. Predict and explain the output of following program

``````r = lambda q: q * 2
s = lambda q: q * 3
x = 2
x = r(x)
x = s(x)
x = r(x)
print x
``````

c. How memory is managed in Python ? Give the tool name that help to find the bugs or perform static analysis ?

Q6.
a. Write a Python program to compute the factorial of a given number using recursion.
b. Define mutable and immutable data type. Explain the concept of Linear and Binary search with Python program.
c. Write Code snippets in Python to perform Accessing Elements of Tuple.

Q7.
a. How will you create a Package and import it ? Explain it with an example program.
b. Explain the following:
1 List Slicing
2 List Accessing Methods

Q8.
a. Illustrate the LEGB rules and its significance with help of suitable diagram.
b. Explain about Python slice. Write the syntax of slice and discuss about it.

Q9.
a. Define NumPy ? How to create NumPy Array ?
b. Explain Flowchart and symbols used in flowchart. Write the Algorithm, pseudo code and draw the flowchart for Towers of Hanoi.