(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 ?
(b) foo
(c) _
(d) 1st_string

1.4 Which of the following is an invalid variable ?

x = [‘ab’,’cd’]
for I in 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):

(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 ?
print (t [3])
(b) t [3] = 45
(c) print (max(t))
(d) print (Len(t))

1.8 What is the output of the following Python code?


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

1.9 Which of the following statements is false about recursion ?
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 ?

m=functools.rediuce(lambda x, y:x if x>y else y, 1)

(a) Error
(b) address of m
(c) 1
(d) 5

2) State which of the following is True or False:- 1×10=10

2.1Python is high-level, interpreted, interactive and object-oriented scripting language. It is designed to be highly unreadable.F
2.2Python is derived from many other languages, including ABC< Modula-3, C, C++, Algol-68, SmallTalk, and Unix shell and other scripting languages.T
2.3In Python assignment of more than one behavior to a particular function and the operation performed varies the types of objects or arguments involved are known as operator overloading.F
2.4To access value in tuple, use the square bracket for slicing along with the index or indices to obtain value available at index.T
2.5The Python standard for database interface is the Python SB-API. Most Python database interfaces adhere to this Standard.T
2.6If a communication is established with the datasource, then a Connection Object is returned and save into db for further use, otherwise db is set to None.T
2.7That tell() method tells you the current position with in the file.T
2.8Removing individual tuple elements is possible.F
2.9The first method_init_() is a special method, which is called class constructor or initialization method that Python Cause when you create a new instance of the class.T
2.10When a python script Raises an exception, it is must either handle the exception immediately otherwise it will terminate and quits.T

3) Match the following:- 1×10=10

3.1Error does not fall into any category (F)A. Time.altzone
3.2The arguments have invalid values specified (D)B. tuple(seq)
3.3Opens a file for both reading and writing in binary format (E)C. tell()
3.4function blocks begin with the keyword (H)D. Value Error
3.5Negative count from the right (G)E. rb+
3.6Method displays the current working directory (J)F. Runtime Error
3.7The offset of the local DST time zone (A)G. L[-2]
3.8Converts a list into tuple (B)H. def
3.9Shows current position within the file (C)I. del
3.10Explicitly remove an entire tuple (I)J. getcwd()
K. Syntax Error
L. Rb-
M. L[-1]

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

a) time.time()b) 24c) parentheses
d) referencee) moref) local variables
g) TRUEh) Guido van Rossumi) function
j) objectk) lessl) FALSE
m) Tim Berner

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”
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)

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 ?

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.

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

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.

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.