Python Programming MCQs [set-2]
26. What is the output of the following program?
def REVERSE(L):
L.reverse()
return(L)
def YKNJS(L):
List = list()
List.extend(REVERSE(L))
print(List)
L = [1, 3.1, 5.31, 7.531]
YKNJS(L)
o m
A. [1, 3.1, 5.31, 7.531]
. c
B. [7.531, 5.31, 3.1, 1]
te
C. IndexError
a
Answer: B
q M
D. AttributeError: „NoneType? object has no attribute „REVERSE?
27. What is the output of theM
c
following program?
from math import sqrt
L1 = [x**2 for x in range(10)].pop()
L1 + = 19
print(sqrt(L1), end = " ")
L1 = [x**2 for x in reversed(range(10))].pop()
L1 + = 16
print(int(sqrt(L1)))
A. 10.0 4.0
B. 4.3588 4
C. 10 .0 4
D. 10.0 0
Answer: C
28. What is the output of the following program?
D = dict()
for x in enumerate(range(2)):
D[x[0]] = x[1]
D[x[1]+7] = x[0]
print(D)
A. KeyError
B. {0: 1, 7: 0, 1: 1, 8: 0}
C. {0: 0, 7: 0, 1: 1, 8: 1}
D. {1: 1, 7: 2, 0: 1, 8: 1}
Answer: C
29. What is the output of the following program?
D = {1 : 1, 2 : '2', '1' : 1, '2' : 3}
D['1'] = 2
print(D[D[D[str(D[1])]]])
A. 2
B. 3
C. „2?
D. KeyError
Answer: B
30. What is the output of the following program?
D = dict()
for i in range (3):
for j in range(2):
D[i] = j
print(D)
A. {0: 0, 1: 0, 2: 0}
B. {0: 1, 1: 1, 2: 1}
C. {0: 0, 1: 0, 2: 0, 0: 1, 1: 1, 2: 1}
D. TypeError: Immutable object
Answer: B
31. What is the output of the following program? from math import *
a = 2.13
b = 3.7777
c = -3.12
print(int(a), floor(b), ceil(c), fabs(c))
View all MCQ's at McqMate.com
A. 2 3 -4 3
B. 2 3 -3 3.12
C. 2 4 -3 3
D. 2 3 -4 3.12
Answer: B
32. What is the output of the following program?
A. [0, „2?, „3?, „4?, „5?, 0]
B. [„6?, „2?, „3?, „5?, „5?, „6?]
C. [„0?, „2?, „3?, „5?, „5?, „0?]
D. [0, „2?, „3?, „5?, „5?, 0]
Answer: D
33. What is the output of the following program?
import string
import string
Line1 = "And Then There Were None"
Line2 = "Famous In Love"
Line3 = "Famous Were The Kol And Klaus"
Line4 = Line1 + Line2 + Line3
print(string.find(Line1, 'Were'), string.count((Line4), 'And'))
A. True 1
B. 15 2
C. (15, 2)
D. True 2
Answer: C
34. What is the output of the following program?
line = "What will have so will"
L = line.split('a')
for i in L:
print(i, end=' ')
A. [„What?, „will?, „have?, „so?, „will?]
B. Wh t will h ve so will
C. What will have so will
D. [„Wh?, „t will h?, „ve so will?]
Answer: B
View all MCQ's at McqMate.com
35. What is the type of each element in sys.argv?
A. set
B. list
C. tuple
D. string
Answer: D
36. What is the length of sys.argv?
A. number of arguments
B. number of arguments + 1
C. number of arguments – 1
D. none of the mentioned
Answer: B
37. What is the output of the following code?
def foo(k):
k[0] = 1
q = [0]
foo(q)
print(q)
A. [0].
B. [1].
C. [1, 0].
D. [0, 1].
Answer: B
38. What is the output of the following code?
def foo(fname, val):
print(fname(val))
foo(max, [1, 2, 3])
foo(min, [1, 2, 3])
A. 3 1
B. 1 3
C. error
D. none of the mentioned
Answer: A
View all MCQ's at McqMate.com
39. What is the output of the following?
elements = [0, 1, 2]
def incr(x):
return x+1
print(list(map(elements, incr)))
A. [1, 2, 3].
B. [0, 1, 2].
C. error
D. none of the mentioned
Answer: C
40. What is the output of the following?
elements = [0, 1, 2]
def incr(x):
return x+1
print(list(map(incr, elements)))
A. [1, 2, 3].
B. [0, 1, 2].
C. error
D. none of the mentioned
Answer: A
41. What is the output of the following?
def to_upper(k):
return k.upper()
x = ['ab', 'cd']
print(list(map(to_upper, x)))
A. [„AB?, „CD?].
B. [„ab?, „cd?].
C. none of the mentioned
D. error
Answer: A
42. What is the output of the following?
x = ['ab', 'cd']
print(len(list(map(list, x))))
A. 2
View all MCQ's at McqMate.com
B. 4
C. error
D. none of the mentioned
Answer: A
43. Program code making use of a given module is called a ______ of the module.
A. Client
B. Docstring
C. Interface
D. Modularity
Answer: A
44. What is the output of the following piece of code?
#mod1
def change(a):
b=[x*2 for x in a]
print(b)
#mod2
def change(a):
b=[x*x for x in a]
print(b)
from mod1 import change
from mod2 import change
#main
s=[1,2,3]
change(s)
A. [2,4,6].
B. [1,4,9].
C. [2,4,6].
D. There is a name clash
Answer: D
45. What is the output of the following program? tday=datetime.date.today()
print(tday.month())
A. August
B. Aug
C. 08
View all MCQ's at McqMate.com
D. 8
Answer: D
46. Which of the following formatting options can be used in order to add „n?
blank spaces after a given string „S??
A. print(“-ns”%S)
B. print(“-ns”%S)
C. print(“%ns”%S)
D. print(“%-ns”%S)
Answer: D
47. What is the output of the following program?
f = None
for i in range (5):
with open("data.txt", "w") as f:
if i > 2:
break
print(f.closed)
A. True
B. False
C. None
D. Error
Answer: A
48. To read the entire remaining contents of the file as a string from a file object
infile, we use
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Answer: B
49. Suppose t = (1, 2, 4, 3), which of the following is incorrect?
A. print(t[3])
B. t[3] = 45
C. print(max(t))
D. print(len(t))
Answer: B
View all MCQ's at McqMate.com