COMPLETE PYTHON PROGRAMMING (FINAL QUIZ) ANSWERS

 


NOTE:- ANSWERS ARE AT THE BOTTOM OF PAGE.



1.

What will be the output of following python code -
str1 = ‘678’
str2 = str1 + 1
print(str2)
2.What will be the output of following python code -
str1 = ‘mobile’
str2 = 4
str3 = str1[str2+1]
print(str3)
3.What will be the output of following python code -
s = ‘Python_Program’
print(s[7:16])
4.What will be the result of evaluating the following python expression:
‘Python’ == ‘python’
5.The following python code is stored in a file code.py. What will be printed if the file is executed using python 3 interpreter?
s = ‘Python’
if ‘h’ in s:
    print(‘present’)
‘a’ in s   
(a) present
     True
(b) present
     False
(c) present
(d) False
6.What will be the output of following python code -
s = ‘butterfly’
pos = s.find(‘t’)
print(pos)
print(pos)
(a) 2
    3
(b) 2
    2
(c) 3
    4
(d) 3
    3
7.What will be the output of following python code -
print(len('X\nY\n\nZn'))
8.What will never be printed as output regardless of the value of x in the following piece of python code -
if x < 5 :
    print('Less than 5')
elif x >= 2 : 
    print('5 or more')
else :
    print('any range')
9.Suppose we have a python module as file mdl.py defining four functions f1, f2, f3 and f4. Now we give following python command at the python shell:
>>> from mdl import f2
Which of the following functions from mdl.py can be invoked from calling script -
10.What will never be printed as output regardless of the value of x in the following piece of python code -
if x < 5 :
    print('Less than 5')
elif x < 25 : 
    print('Less than 25')
elif x < 15 :
    print(‘Less than 15’)
else :
    print('any range')
11.Which of the following words can be used as variable name/identifier in python:
12.Which of the following is a valid variable name/identifier in python -
x = 1+2**3/4*5
print(x)
13.Comments in a python program are useful because -
14.When we put an integer and floating point in an expression, the floating point is implicitly converted to an integer.
15.Which of the following is a valid variable name/identifier in python -
16.What is the output of the following python code?
x = 100
def func():
    x = 4
    print('x is', x)
    print('Changed global x to', x)
func()
print('Value of x is', x)
(a) x is 100
Changed global x to 4
Value of x is 100
(b) x is 100
Changed global x to 4
Value of x is 4
(c) x is 100
Changed global x to 100
Value of x is 100
(d)  x is 4
Changed global x to 4
Value of x is 100
17.What is the output of the following python code?
z={1,2,3}
z.update([1,2,3])
print(z)
22.What will be the output of following python code -
s = 'abca'
it = iter(s)
next(it)
next(it)
next(it)
print(next(it))
23.Which of the following sorting algorithms will take least estimated run time if input list of n numbers is already sorted.
24.What is the output of following python code -
a = True
b = False
c = False
if not a or b:
    print('a')
elif not a or not b and c:
    print('b')
elif not a or b or not b and a:
    print('c')
else:
    print('d')
25.What is the output of following python code -
def fn(a,b):
    v=1
    b[0]=100
t=3
v=[1,2,3]
fn(t,v)
print(t,v[0])
26.What will be the output of following python code -
print(0.3 + 0.4 == 0.7)
28.What is the output of following python code -
a = [[7, 8, 9], [4, 5, 6], [1, 2, 3]]
print(a[2])
29.What will be the output of the following python code -
“Academics”[ : : -1]
31.What will be the output of the following python code -
def f(): 
    pass
print(type(f()))
(a) <class ‘void’
(b) <class ‘NoneType’>
(c) <class ‘None’>
(d) <class ‘str’>
32.Consider a python script, p1.py, containing the following -
n = 5
while n > 0 :
    print('A')
    print('B')
print('C')

Consider another python script, p2.py, containing the following -
n = 0
while n > 0 :
    print('A')
    print('B')
print('C')
Now which of the following is FALSE:
33.The continue statement ends the current loop and jumps to the statement immediately following the loop. On the other hand, the break statement ends the current iteration and jumps to the top of the loop and starts the next iteration.
34.What is the output of following python code -
x = None
for value in [3, 41, 12, 9, 74, 15] :
    if x is None : 
        x = value
    elif value < x : 
        x = value
print(x)
35.In python, strings are mutable while lists are immutable.
36.What is the output of following python code -
a = [1, 2, 3]
b = [1, 2, 3]
c = a + b
print(c)
37.In python, tuples are mutable.
38.What is the output of following python code
a = (4, 9, 2)
a.sort()
print(a)
39.Which of the following is/are the feature/features of inheritance -
40.In object oriented programming, a constructor in a class is a method called when an object is created.
41.What is the correct match of column 1 with column 2 -
 Column 1                         Column 2

(1) Class                     (5) A particular instance of a class

(2) Attribute                 (6) A function within a class

(3) Method                    (7) A template

(4) Object                    (8) A variable within a class
42.In python, what is a variable defined outside a function referred to as -
43.Which is the most efficient (based on estimated worst case run time) sorting algorithm among the following -
44.If we want to perform relational operation ‘<’ between two objects then which special method is called in python -
45.What is the output of the following python code -
def xyz(i = 4, j = 3):
    i = i + j
    j = j + 1
    print(i, j)
xyz(j = 1, i = 2)


Answers.

1. d
2. b
3. a
4. b
5. c
6. b
7. d
8. c
9. b
10. d
11. b
12. c
13. d
14. a
15. d
16. d
17. b
22. a
23. d
24. c
25. d
26. a
28. d
29. a
31. b
32. b
33. b
34. d
35. b
36. d
37. b
38. c
39. d
40. a
41. c
42. b
43. c
44. b
45. d

Post a Comment

0 Comments