2.Python Unit 2 Question Bank
2.Python Unit 2 Question Bank
Multiple Choice
Identify the choice that best completes the statement or answers the question.
____ 1. Python converts the source code into an intermediate form called___
a. Object code
b. Byte Code
c. Machine code
d. Virtual code
a. Interpreted
b. reliable
c. simple
d. All of these
a. /
b. //
c. %
d. *
a. "Computer"
b. 'Computer'
c. "'Computer'"
d. All of these
a. U
b. R
c. 5
d. A
a. 23.0
b. 1/3
c. 15
d. ABC
a. 10.345
b. '9'
c. 9
d. "9"
a. 00
b. //
c. #
d. *
____ 13. All keywords in Python are in
a. lower case
b. UPPER CASE
c. Capitalized
d. none
____ 14. Which of the following cannot be a variable?
a. __init__
b. in
c. it
d. on
____ 15. What is the output when following code is executed ?
>>> print(r"\nhello")
The output is
a. a new line and hello
b. \nhello
c. the letter r and then hello
d. Error
____ 16. What is the output when following statement is executed ?
>>>print("new" "line")
a. Error
b. Output equivalent to print ‘new\nline’
c. newline
d. new line
____ 17. what is the output:
>>> print 0xA + 0xB + 0xC :
a. 0xA0xB0xC
b. Error
c. 0x22
d. 33
____ 18. What is the output of “hello”+1+2+3 ?
a. hello123
b. hello
c. Error
d. hello6
____ 19. What is the output when following code is executed ?
>>>print("D", end = ',')
>>>print("C", end = ',')
>>>print("B", end = ',')
>>>print("A", end = ',')
a. DCBA
b. A, B, C, D
c. D C B A
d. D, C, B, A will be displayed on four lines
e. None of these
____ 20. What is the output when following statement is executed?(python 3.xx)
>>>print(format("Welcome", "10s"), end = '#')
>>>print(format(111, "4d"), end = '#')
>>>print(format(924.656, "3.2f"))
a. Welcome# 111#924.66
b. Welcome#111#924.66
c. Welcome#111#.66
d. Welcome # 111#924.66
____ 21. Say s=”hello” what will be the return value of type(s)?
a. int
b. bool
c. str
d. String
____ 22. What is the output of this code?
b. An error message
a. "one" + "2"
b. '5' + 6
c. 3 + 4
d. "7" + 'eight'
>>>spam = "eggs"
>>>print(spam*3)
a. Spamspamspam
b. eggseggseggs
c. "spamspamspam"
d. spam*3
>>>int("39" + "49")
a. 007900
b. 00394900
c. 3949
d. (003900+ 004900)
Enter a number: 3
a. 0012312312300
b. 00369.900
c. 123123123.0
d. 369.9
____ 27. What will be the status of the following list after fourth pass of bubble sort used for arranging the
following elements in descending order? {34, –6, 12, –3, 45, 25}
a. This is a variable
b. This_Is_A_VARIABLE
c. This-is-a-variable
d. ^var
a. remove
b. clear
c. del
d. delete
a. ,
b. ;
c. :
d. /
a. integer
b. float
c. string
d. character
a. integer
b. float
c. string
d. list
a. Relational
b. Arithmetic
c. Bitwise
d. Logical
a. +
b. *
c. &
d. "
a. 5
b. 17
c. 7
d. "7"
a. True
b. False
a. 11(12+13)
b. (5*6)(7+8)
c. 4*(3-2)
d. 5***3
a. 56.789
b. 5.6789
c. 0.56789
d. 56789
a. 1
b. 2
c. 3
d. 4
overflow.
a. a*b
b. a**b
c. a/b
d. a+b
____ 50. Which statement ends the current iteration of the loop and continues with the next one?
a. break
b. continue
c. skip
d. pass
____ 51. Which statement is used to terminate the execution of the nearest enclosing loop in which it appears?
a. pass
b. break
c. continue
d. jump
a. pass
b. break
c. continue
d. jump
a. pass
b. break
c. continue
d. jump
____ 55. What is the data type of x after the following statement?
x = ['Today', 'Tomorrow', 'Yesterday']
a. List
b. Dictionary
c. Tuple
d. String
____ 56. What would happen if we replace the break statement in the code with a 'continue'?
True or False
a. True
b. False
____ 58. Which data type will you use to represent the following data values?
a. integer
b. float
c. string
d. complex
a. 5678
b. 5,678
c. 5678.0
d. 0.5678
e. 0.56e+10
a. integer
b. string
c. complex number
d. float
>>>str="hello"
>>>str[:2]
>>>
a. he
b. lo
c. olleh
d. hello
____ 64. What is the return type of function id ?
a. int
b. float
c. bool
d. dict
____ 65. What error occurs when you execute?
apple = mango
a. SyntaxError
b. NameError
c. ValueError
d. TypeError
____ 66. Carefully observe the code and give the answer.
def example(a):
a = a + '2'
a = a*2
return a
>>>example("hello")
a. indentation Error
b. cannot perform mathematical operation on strings
c. hello2
d. hello2hello2
____ 67. What dataype is the object below ?
L = [1, 23, ‘hello’, 1]
a. List
b. dictionary
c. array
d. tuple
____ 68. In order to store values in terms of key and value we use what core datatype.
a. List
b. tuple
c. class
d. dictionary
____ 69. What will be the output after the following?
for i in range(1,5):
print(i, end='')
a. 15
b. 12345
c. 1234
d. 012345
____ 70. What will be the output after the following?
for i in range(1,25,5):
print(i, end=' ')
a. 1 6 11 16 21
b. 1 5 10 15 20 25
c. 1 5 25
d. 16111621
____ 71. What will be the output after the following?
for i in range(5):
print(i, end='')
a. 5
b. 1 5
c. 012345
d. 01234
____ 72. What will be the output after the following?
x = 'Python'
y = 'y' in x
print(y)
a. [1]
b. y
c. True
d. False
____ 73. What is the output when following statement is executed ?
>>>"a"+"bc"
a. a
b. bc
c. bca
d. abc
____ 74. What is the average value of the code that is executed below ?
>>>grade1 = 80
>>>grade2 = 90
>>>average = (grade1 + grade2) / 2
a. 85
b. 85.0
c. 95
d. 95.0
____ 75. Which part of if statement should be indented?
d. None of these
____ 76. What will be the output after the following statements?
x = 80
y = 50
z = y if (y > x) else x
print(z)
a. 1
b. 0
c. 50
d. 80
____ 77. Which of the following is placed after the if condition?
a. ;
b. .
c. :
d. ,
i = 10
while True:
print(i)
i=i-1
if i<=7:
break
a. 1
b. 2
c. 3
d. 4
____ 79. What is the return value of trunc() ?
a. int
b. bool
c. float
d. None
____ 80. What will be the data type of x after the following statement?
x = (34, 81, 50)
a. List
b. String
c. Dictionary
d. Tuple
____ 81. How many lines will be printed by this code?
while False:
print("Hello")
a. 1
b. 0
c. 10
d. countless
i=5
while i>=0:
print(i)
i=i-1
a. 5
b. 6
c. 4
d. 0
>>>str="hello"
>>>str[:2]
>>>
a. he
b. lo
c. olleh
d. hello
____ 91. What is the output when following statement is executed ?
>>>"abcd"[2:]
a. a
b. ab
c. cd
d. dc
____ 92. What is the output when following code is executed ?
>>> str1 = 'hello'
>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]
a. olleh
b. hello
c. h
d. o
____ 93. Which of the following is an invalid statement?
a. abc = 1,000,000
b. a b c = 1000 2000 3000
c. a,b,c = 1000, 2000, 3000
d. a_b_c = 1,000,000
x = 20
y = 40
z = y if (y > x) else x
print(z)
____ 94. What will be the output after the above statements?
a. True
b. False
c. 20
d. 40
e. Error
x = 65
y = 53
z = y if (x % 2 == 0) else x
print(z)
____ 95. What will be the output after the above statements?
a. True
b. False
c. 65
d. 53
____ 96. What will be the data type of x after the above statement if input entered is 18 ?
a. Float
b. String
c. List
d. Integer
x = ['Today', 'Tomorrow', 'Yesterday']
____ 97. What is the data type of x after the above statement?
a. List
b. Dictionary
c. Tuple
d. String
____ 98. What will be the output after the above statements?
a. x0
b. 25
c. 35
d. 45
____ 99. What will be the output after the above statements?
a. 1.0
b. 4.0
c. 5.0
d. 6.0
x = [5, 4, 3, 2]
x.insert(1, 0)
print(x)
____ 100. What will be the output after the above statements?
a. [5, 1, 3, 2, 0]
b. [5, 0, 4, 3, 2]
c. [0, 5, 4, 3, 2]
d. [1, 5, 4, 3, 2]
x = [5, 4, 3, 2, 1]
y = [10, 5, 0]
x.extend(y)
print(y)
____ 101. What will be the output after the above statements?
a. [5, 4, 3, 2, 1, 10, 5, 0]
b. []
c. [10, 5, 0, 5, 4, 3, 2, 1]
d. [10, 5, 0]
____ 102. What will be the output after the above statements?
a. ['Today', 'Sunday', '15', '25', '53']
b. ['Sunday', 'Today', '15', '25', '53']
c. ['15', '25', '53', 'Sunday', 'Today']
d. ['15', '25', '53', 'Today', 'Sunday']
x = [5, 3, 6, 2, 4, 0, 7]
del x[0:4]
print(x)
____ 103. What will be the output after the above statements?
a. []
b. [5, 3, 6, 2, 7]
c. [5, 3, 6, 2, 4, 0]
d. [4, 0, 7]
x=8
if x > 8:
print(20)
else:
print(10)
____ 104. What will be the output after the above statements?
a. 20
b. x
c. 10
d. 8
x = 40
if x > 10:
print(20)
elif x == 40:
print(10)
else:
print(30)
____ 105. What will be the output after the above statements?
a. 20
b. 40
c. 10
d. 30
x = 15
if x > 15:
print(0)
elif x == 15:
print(1)
else:
print(2)
____ 106. What will be the output after the above statements?
a. 0
b. 1
c. 2
d. 15
x=5
if x > 15:
print('yes')
elif x == 15:
print('equal')
else:
print('no')
____ 107. What will be the output after the above statements?
a. 15
b. yes
c. equal
d. no
x=1
while x < 10:
print(x, end='')
x=x+1
____ 108. What will be the output after the above statements?
a. 123456789
b. 1
c. 10
d. 2
x=0
while x < 10:
print(x, end='')
x += 4
____ 109. What will be the output after the above statements?
a. 0123456789
b. 123456789
c. 4123456789
d. 048
x=0
y=4
while x + y < 10:
print(x, end='')
x += 1
____ 110. What will be the output after the above statements?
a. 012345
b. 0123456789
c. 4123456789
d. 048
for i in range(1,5):
print(i, end='')
if i == 3:
break
____ 111. What will be the output after the above statements?
a. 123
b. 1234
c. 12
d. 12345
for i in range(1,5):
if i == 3:
continue
print(i, end=' ')
____ 112. What will be the output after the above statements?
a. 1 2 4
b. 1 2 3 4
c. 1 2
d. 1 2 3
Multiple Response
Identify one or more choices that best complete the statement or answer the question.
a. this_is_a_variable
b. 123abc = 19.22
c. ThisBook = "Python"
d. %name = "xyz"
____ 114. Which of the following will run without errors(multiple answers possible) ?
a. round(45.8)
b. round(6352.898,2)
c. round()
d. round(7463.123,2,1)
____ 115. Select all options that print
hello-how-are-you
a. print('hello', 'how', 'are', 'you')
b. print('hello', 'how', 'are', 'you' + '-' * 4)
c. print('hello-' + 'how-are-you')
d. print('hello' + '-' + 'how' + '-' + 'are' + '-' + 'you')
____ 116. The following is displayed by a print function call:
tom
dick
harry
Select all of the function calls that result in this output
a. print('"tom
\ndick
\nharry"')
b. print(”’tom
dick
harry”’)
c. print(‘tom\ndick\nharry’)
d. print(‘tom \
dick\
harry’)
____ 117. In python we do not specify types,it is directly interpreted by the compiler, so consider the following
operation to be performed.
>>>x = 13 / 2
objective is to make sure x has a integer value, select all that apply (python 3.xx)
a. x = 13 // 2
b. x = int(13 / 2)
c. x = 13 / 2
d. x = 13 % 2
____ 118. Which of the following results in a SyntaxError?(Multiple answers possible)
a. '"Once upon a time…", she said.'
b. "He said, "Yes!""
c. '3\'
d. "'That's okay"
QBForUnit2cit1
Answer Section
MULTIPLE CHOICE
1. ANS: B PTS: 1
2. ANS: D PTS: 1
3. ANS: A PTS: 1 REF: Variable names can be of any length.
4. ANS: A PTS: 1 REF: eval can be used as a variable.
5. ANS: A PTS: 1 REF: Case is always significant.
6. ANS: D PTS: 1
REF: All the statements will execute successfully but at the cost of reduced readability.
7. ANS: C PTS: 1
8. ANS: D PTS: 1
9. ANS: A PTS: 1
10. ANS: C PTS: 1
11. ANS: B PTS: 1
12. ANS: C PTS: 1
13. ANS: D PTS: 1
REF: True, False and None are capitalized while the others are in lower case.
14. ANS: B PTS: 1 REF: in is a keyword.
15. ANS: B PTS: 1 DIF: 1 TOP: 2
16. ANS: C PTS: 1 DIF: 1 TOP: 2
17. ANS: D PTS: 1 DIF: 1 TOP: 2
18. ANS: C PTS: 1
19. ANS: E PTS: 1 DIF: 1 TOP: 2
20. ANS: D PTS: 2 DIF: 1 TOP: 2
21. ANS: C PTS: 1 DIF: 1 TOP: 2
22. ANS: A PTS: 1
23. ANS: B PTS: 1
24. ANS: B PTS: 1
25. ANS: C PTS: 1
26. ANS: C PTS: 2 DIF: 2
27. ANS: D PTS: 2 DIF: 2 TOP: 2
28. ANS: B PTS: 1
29. ANS: C PTS: 1
30. ANS: B PTS: 1
31. ANS: C PTS: 1
32. ANS: A PTS: 1
33. ANS: C PTS: 1
34. ANS: B PTS: 1
35. ANS: A PTS: 1
36. ANS: A PTS: 1
37. ANS: D PTS: 1
38. ANS: B PTS: 1 REF: In python, power operator is x**y i.e. 2**3=8.
39. ANS: A PTS: 1 REF: For order of precedence, just remember this
PEDMAS.
40. ANS: A PTS: 1 REF: None.
41. ANS: C PTS: 1
REF: First this expression will solve 1**3 because exponential have higher precedence than
multiplication, so 1**3 = 1 and 3*1 = 3. Final answer is 3.
42. ANS: C PTS: 1 REF: None.
43. ANS: D PTS: 1 REF: None.
44. ANS: A PTS: 1
REF: This statement is true in Python 2.7 but not in Python 3! In Python 3, you must use // if you want
integer division.
45. ANS: B PTS: 1
46. ANS: C PTS: 1
47. ANS: A PTS: 1
48. ANS: D PTS: 1
49. ANS: B PTS: 1
50. ANS: B PTS: 1
51. ANS: B PTS: 1
52. ANS: B PTS: 1
53. ANS: C PTS: 1
54. ANS: A PTS: 1
55. ANS: A PTS: 1
56. ANS: B PTS: 1
57. ANS: B PTS: 1
58. ANS: A PTS: 1
59. ANS: A PTS: 1
60. ANS: C PTS: 1
61. ANS: D PTS: 1 DIF: 1 REF: Class is a user defined datatype.
TOP: 2
62. ANS: D PTS: 1 DIF: 1 TOP: 2
63. ANS: A PTS: 1 DIF: 1
REF: We are printing only the 1st two bytes of string and hence the answer is “he”.
TOP: 2
64. ANS: A PTS: 1 DIF: 1
REF: Execute help(id) to find out details in python shell.id returns a integer value that is unique.
TOP: 2
65. ANS: B PTS: 1 DIF: 1
REF: mango is not defined hence name error. TOP: 2
66. ANS: A PTS: 1 DIF: 1
REF: Python codes have to be indented properly. TOP: 2
67. ANS: A PTS: 1 DIF: 1
REF: List datatype can store any values within it. TOP: 2
68. ANS: D PTS: 1 DIF: 1
REF: Dictionary stores values in terms of keys and values. TOP: 2
69. ANS: C PTS: 1
70. ANS: A PTS: 1
71. ANS: D PTS: 1
72. ANS: C PTS: 1
73. ANS: D PTS: 1 DIF: 1 TOP: 2
74. ANS: B PTS: 1 DIF: 1
REF: Cause a decimal value to appear as output. TOP: 2
75. ANS: C PTS: 1
76. ANS: D PTS: 1
77. ANS: C PTS: 1
78. ANS: C PTS: 1
79. ANS: A PTS: 1 DIF: 1
REF: Executle help(math.trunc) to get details. TOP: 2
80. ANS: D PTS: 1
81. ANS: B PTS: 1
82. ANS: A PTS: 1
83. ANS: B PTS: 1
84. ANS: C PTS: 1
85. ANS: D PTS: 1
86. ANS: D PTS: 1 REF: Identifiers can be of any length.
87. ANS: B PTS: 1 REF: Variable names should not start with a number.
88. ANS: A PTS: 1
REF: As Python has no concept of private variables, leading underscores are used to indicate variables
that must not be accessed from outside the class.
89. ANS: A PTS: 1
90. ANS: A PTS: 1
REF: We are printing only the 1st two bytes of string and hence the answer is “he”.
91. ANS: C PTS: 1 DIF: 1 TOP: 2
92. ANS: D PTS: 1 DIF: 1 TOP: 2
93. ANS: B PTS: 1 REF: Spaces are not allowed in variable names.
94. ANS: D PTS: 1
95. ANS: C PTS: 1
96. ANS: B PTS: 1
97. ANS: A PTS: 1
98. ANS: B PTS: 1
99. ANS: C PTS: 1
100. ANS: B PTS: 1
101. ANS: D PTS: 1
102. ANS: C PTS: 1
103. ANS: D PTS: 1
104. ANS: C PTS: 1
105. ANS: A PTS: 1
106. ANS: B PTS: 1
107. ANS: D PTS: 1
108. ANS: A PTS: 1
109. ANS: D PTS: 1
110. ANS: A PTS: 1
111. ANS: A PTS: 1
112. ANS: A PTS: 1
MULTIPLE RESPONSE
113. ANS: A, C PTS: 1
114. ANS: A, B PTS: 2 DIF: 1
REF: Execute help(round) in the shell to get details of the parameters that are passed into the round
function. TOP: 2
115. ANS: C, D PTS: 2 DIF: 1 REF: Execute in the shell.
TOP: 2
116. ANS: C PTS: 2 DIF: 1
REF: The \n adds a new line and \ allows the string to extend. TOP: 2
117. ANS: A, B PTS: 2 DIF: 1
REF: // is integer operation in python 3.0 and int(..) is a type cast operator.
TOP: 2
118. ANS: B, C PTS: 2 DIF: 1 REF: Carefully look at the quotes
TOP: 2