Python Programming (2180711) MCQs

MCQs of Introduction to Python

Showing 161 to 160 out of 170 Questions
161.
What will be the output of the following Python code snippet? x = 2 for i in range(x): x += 1 print (x)
(a) 0 1 2 3 4 …
(b) 0 1
(c) 3 4
(d) 0 1 2 3
Answer:

Option (c)

162.
What will be the output of the following Python code snippet? x = 2 for i in range(x): x -= 2 print (x)
(a) 0 1 2 3 4 …
(b) 0 -2
(c) 0
(d) error
Answer:

Option (b)

163.
What will be the output of the following Python code? for i in range(10): if i == 5: break else: print(i) else: print(""Here"")
(a) 0 1 2 3 4 Here
(b) 0 1 2 3 4 5 Here
(c) 0 1 2 3 4
(d) 1 2 3 4 5
Answer:

Option (c)

164.
What will be the output of the following Python code? for i in range(5): if i == 5: break else: print(i) else: print(""Here"")
(a) 0 1 2 3 4 Here
(b) 0 1 2 3 4 5 Here
(c) 0 1 2 3 4
(d) 1 2 3 4 5
Answer:

Option (a)

165.
What will be the output of the following Python code? x = (i for i in range(3)) for i in x: print(i)
(a) 2000 1 2
(b) error
(c) 0 1 2 0 1 2
(d) none of the mentioned
Answer:

Option (a)

166.
What will be the output of the following Python code? x = (i for i in range(3)) for i in x: print(i) for i in x: print(i)
(a) 2000 1 2
(b) error
(c) 0 1 2 0 1 2
(d) none of the mentioned
Answer:

Option (a)

167.
What will be the output of the following Python code? string = ""my name is x"" for i in string: print (i, end="", "")
(a) m, y, , n, a, m, e, , i, s, , x,
(b) m, y, , n, a, m, e, , i, s, , x
(c) my, name, is, x,
(d) error
Answer:

Option (a)

168.
What will be the output of the following Python code snippet? a = [0, 1, 2, 3] for a[-1] in a: print(a[-1])
(a) 0 1 2 3
(b) 0 1 2 2
(c) 3 3 3 3
(d) error
Answer:

Option (b)

169.
What will be the output of the following Python code snippet? a = [0, 1, 2, 3] for a[0] in a: print(a[0])
(a) 0 1 2 3
(b) 0 1 2 2
(c) 3 3 3 3
(d) error
Answer:

Option (a)

170.
What will be the output of the following Python code snippet? a = [0, 1, 2, 3] i = -2 for i not in a: print(i) i += 1
(a) -2 -1
(b) 0
(c) error
(d) none of the mentioned
Answer:

Option (c)

Showing 161 to 160 out of 170 Questions