0% found this document useful (0 votes)
23 views9 pages

3 MCQ Class 11th While and For Loops

The document contains multiple-choice questions (MCQs) focused on Python's while and for loops, designed to test understanding of loop behavior and outputs. Each question presents a code snippet followed by four answer options. The content is structured into sections, with various examples illustrating different aspects of loop functionality in Python.

Uploaded by

Palak Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views9 pages

3 MCQ Class 11th While and For Loops

The document contains multiple-choice questions (MCQs) focused on Python's while and for loops, designed to test understanding of loop behavior and outputs. Each question presents a code snippet followed by four answer options. The content is structured into sections, with various examples illustrating different aspects of loop functionality in Python.

Uploaded by

Palak Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

MCQ PYTHON WHILE AND FOR LOOPS By Gajendra Sir Mo. No.

: 9810301034
WHILE AND FOR LOOPS – 1
1. What is the output of the following?
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
a) [‘ab’, ‘cd’]. b) [‘AB’, ‘CD’]. c) [None, None]. d) none of the mentioned
2. What is the output of the following?
x = ['ab', 'cd']
for i in x:
x.append(i.upper())
print(x)
a) [‘AB’, ‘CD’]. b) [‘ab’, ‘cd’, ‘AB’, ‘CD’]. c) [‘ab’, ‘cd’]. d) none of the mentioned
3. What is the output of the following?
i=1
while True:
if i%3 == 0:
break
print(i)
i+=1
a) 1 2 b) 1 2 3 c) error d) none of the mentioned
4. What is the output of the following?
i=1
while True:
if i%0o7 == 0:
break
print(i)
i += 1
a) 1 2 3 4 5 6 b) 1 2 3 4 5 6 7 c) error d) none of the mentioned
5. What is the output of the following?
i=5
while True:
if i%0o11 == 0:
break
print(i)
i += 1
a) 5 6 7 8 9 10 b) 5 6 7 8 c) 5 6 d) error
6. What is the output of the following?
i=5
while True:
if i%0o9 == 0:
break
print(i)
i += 1
a) 5 6 7 8 b) 5 6 7 8 9 c) 5 6 7 8 9 10 11 12 13 14 15 …. d) error
7. What is the output of the following?
i=1
while True:
if i%2 == 0:
break
print(i)
i += 2

Page 1 of 9 Computer Science 083 PYTHON pgt.csip.gajedra@gmail.com


MCQ PYTHON WHILE AND FOR LOOPS By Gajendra Sir Mo. No. : 9810301034
a) 1 b) 1 2 c) 1 2 3 4 5 6 … d) 1 3 5 7 9 11 …
8. What is the output of the following?
i=2
while True:
if i%3 == 0:
break
print(i)
i += 2
a) 2 4 6 8 10 … b) 2 4 c) 2 3 d) error
9. What is the output of the following?
i=1
while False:
if i%2 == 0:
break
print(i)
i += 2
a) 1 b) 1 3 5 7 … c) 1 2 3 4 … d) none of the mentioned
10. What is the output of the following?
True = False
while True:
print(True)
break
a) True b) False c) None d) none of the mentioned
WHILE AND FOR LOOPS – 2
1. What is the output of the following?
i=0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
a) 0 1 2 0 b) 0 1 2 c) error d) none of the mentioned
2. What is the output of the following?
i=0
while i < 3:
print(i)
i += 1
else:
print(0)
a) 0 1 2 3 0 b) 0 1 2 0 c) 0 1 2 c) error
3. What is the output of the following?
x = "abcdef"
while i in x:
print(i, end=" ")
a) a b c d e f b) abcdef c) i i i i i i … d) error
4. What is the output of the following?
x = "abcdef"
i = "i"
while i in x:
print(i, end=" ")

Page 2 of 9 Computer Science 083 PYTHON pgt.csip.gajedra@gmail.com


MCQ PYTHON WHILE AND FOR LOOPS By Gajendra Sir Mo. No. : 9810301034
a) no output b) i i i i i i … c) a b c d e f d) abcdef
5. What is the output of the following?
x = "abcdef"
i = "a"
while i in x:
print(i, end = " ")
a) no output b) i i i i i i … c) a a a a a a … d) a b c d e f
6. What is the output of the following?
x = "abcdef"
i = "a"
while i in x:
print('i', end = " ")
a) no output b) i i i i i i … c) a a a a a a … d) a b c d e f
advertisement
7. What is the output of the following?
x = "abcdef"
i = "a"
while i in x:
x = x[:-1]
print(i, end = " ")
a) i i i i i I b) a a a a a a c) a a a a a d) none of the mentioned
8. What is the output of the following?
x = "abcdef"
i = "a"
while i in x[:-1]:
print(i, end = " ")
a) a a a a a b) a a a a a a c) a a a a a a … d) a
9. What is the output of the following?
x = "abcdef"
i = "a"
while i in x:
x = x[1:]
print(i, end = " ")
a) a a a a a a b) a c) no output d) error
10. What is the output of the following?
x = "abcdef"
i = "a"
while i in x[1:]:
print(i, end = " ")
a) a a a a a a b) a c) no output d) error
WHILE AND FOR LOOPS – 3
1. What is the output of the following?
x = 'abcd'
for i in x:
print(i)
x.upper()
a) a B C D b) a b c d c) A B C D d) error
2. What is the output of the following?
x = 'abcd'
for i in x:
print(i.upper())
a) a b c d b) A B C D c) a B C D d) error

Page 3 of 9 Computer Science 083 PYTHON pgt.csip.gajedra@gmail.com


MCQ PYTHON WHILE AND FOR LOOPS By Gajendra Sir Mo. No. : 9810301034
3. What is the output of the following?
x = 'abcd'
for i in range(x):
print(i)
a) a b c d b) 0 1 2 3 c) error d) none of the mentioned
4. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
print(i)
a) a b c d b) 0 1 2 3 c) error d) 1 2 3 4
5. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
print(i.upper())
a) a b c d b) 0 1 2 3 c) error d) 1 2 3 4
6. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
i.upper()
print (x)
a) a b c d b) 0 1 2 3 c) error d) none of the mentioned
7. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
x[i].upper()
print (x)
a) abcd b) ABCD c) error d) none of the mentioned
8. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
i[x].upper()
print (x)
a) abcd b) ABCD c) error d) none of the mentioned
9. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
x = 'a'
print(x)
a) a b) abcd abcd abcd c) a a a a d) none of the mentioned
10. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
print(x)
x = 'a'
a) a b) abcd abcd abcd abcd c) a a a a d) none of the mentioned

While and For Loops – 4


1. What is the output of the following?
x = 123
for i in x:
print(i)
a) 1 2 3 b) 123 c) error d) none of the mentioned

Page 4 of 9 Computer Science 083 PYTHON pgt.csip.gajedra@gmail.com


MCQ PYTHON WHILE AND FOR LOOPS By Gajendra Sir Mo. No. : 9810301034
2. What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for i in d:
print(i)
a) 0 1 2 b) a b c c) 0 a 1 b 2 c d) none of the mentioned
3. What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for x, y in d:
print(x, y)
a) 0 1 2 b) a b c c) 0 a 1 b 2 c d) none of the mentioned
4. What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for x, y in d.items():
print(x, y)
a) 0 1 2 b) a b c c) 0 a 1 b 2 c d) none of the mentioned
5. What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for x in d.keys():
print(d[x])
a) 0 1 2 b) a b c c) 0 a 1 b 2 c d) none of the mentioned
6. What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for x in d.values():
print(x)
a) 0 1 2 b) a b c c) 0 a 1 b 2 c d) none of the mentioned
7. What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for x in d.values():
print(d[x])
a) 0 1 2 b) a b c c) 0 a 1 b 2 c d) none of the mentioned
8. What is the output of the following?
d = {0, 1, 2}
for x in d.values():
print(x)
a) 0 1 2 b) None None None c) error d) none of the mentioned
9. What is the output of the following?
d = {0, 1, 2}
for x in d:
print(x)
a) 0 1 2 b) {0, 1, 2} {0, 1, 2} {0, 1, 2} c) error d) none of the mentioned
10. What is the output of the following?
d = {0, 1, 2}
for x in d:
print(d.add(x))
a) 0 1 2 b) 0 1 2 0 1 2 0 1 2 … c) None None None d) None of the mentioned
11. What is the output of the following?
for i in range(0):
print(i)
a) 0 b) no output c) error d) none of the mentioned
While and For Loops – 5
1. What is the output of the following?
for i in range(2.0):

Page 5 of 9 Computer Science 083 PYTHON pgt.csip.gajedra@gmail.com


MCQ PYTHON WHILE AND FOR LOOPS By Gajendra Sir Mo. No. : 9810301034
print(i)
a) 0.0 1.0 b) 0 1 c) error d) none of the mentioned
2. What is the output of the following?
for i in range(int(2.0)):
print(i)
a) 0.0 1.0 b) 0 1 c) error d) none of the mentioned
3. What is the output of the following?
for i in range(float('inf')):
print (i)
a) 0.0 0.1 0.2 0.3 … b) 0 1 2 3 … c) 0.0 1.0 2.0 3.0 … d) none of the mentioned
4. What is the output of the following?
for i in range(int(float('inf'))):
print (i)
a) 0.0 0.1 0.2 0.3 … b) 0 1 2 3 … c) 0.0 1.0 2.0 3.0 … d) none of the mentioned
5. What is the output of the following?
for i in [1, 2, 3, 4][::-1]:
print (i)
a) 1 2 3 4 b) 4 3 2 1 c) error d) none of the mentioned
6. What is the output of the following?
for i in ''.join(reversed(list('abcd'))):
print (i)
a) a b c d b) d c b a c) error d) none of the mentioned
7. What is the output of the following?
for i in 'abcd'[::-1]:
print (i)
a) a b c d b) d c b a c) error d) none of the mentioned
8. What is the output of the following?
for i in '':
print (i)
a) None b) (nothing is printed) c) error d) none of the mentioned
9. What is the output of the following?
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
10. What is the output of the following?
x=2
for i in range(x):
x -= 2
print (x)
a) 0 1 2 3 4 … b) 0 -2 c) 0 d) error
While and For Loops – 6
1. What is the output of the following?
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

Page 6 of 9 Computer Science 083 PYTHON pgt.csip.gajedra@gmail.com


MCQ PYTHON WHILE AND FOR LOOPS By Gajendra Sir Mo. No. : 9810301034
2. What is the output of the following?
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
3. What is the output of the following?
x = (i for i in range(3))
for i in x:
print(i)
a) 0 1 2 b) error c) 0 1 2 0 1 2 d) none of the mentioned
4. What is the output of the following?
x = (i for i in range(3))
for i in x:
print(i)
for i in x:
print(i)
a) 0 1 2 b) error c) 0 1 2 0 1 2 d) none of the mentioned
5. What is the output of the following?
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
6. What is the output of the following?
string = "my name is x"
for i in string.split():
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
7. What is the output of the following?
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
8. What is the output of the following?
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
9. What is the output of the following?
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
10. What is the output of the following?
string = "my name is x"
for i in ' '.join(string.split()):
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

Page 7 of 9 Computer Science 083 PYTHON pgt.csip.gajedra@gmail.com


MCQ PYTHON WHILE AND FOR LOOPS By Gajendra Sir Mo. No. : 9810301034

WHILE AND FOR LOOPS – 1 REASION


Ans 1. a [ The function upper() does not modify a string in place, it returns a new string which isn’t being
stored anywhere. ]
Ans 2. d [ The loop does not terminate as new elements are being added to the list in each iteration. ]
Ans 3. c [ SyntaxError, there shouldn’t be a space between + and = in +=.]
Ans 4. a [ Control exits the loop when i becomes 7. ]
Ans 5. b [ 0O11 is an octal number. ]
Ans 6. d [ 9 isn’t allowed in an octal number. ]
Ans 7. d [ The loop does not terminate since i is never an even number. ]
Ans 8. b [ The numbers 2 and 4 are printed. The next value of i is 6 which is divisible by 3 and hence control
exits the loop. ]
Ans 9. d [ Control does not enter the loop because of False. ]
WHILE AND FOR LOOPS – 2 REASION
Ans 1. b [ The else part is not executed if control breaks out of the loop. ]
Ans 2. b [ The else part is executed when the condition in the while statement is false. ]
Ans 3. d [ NameError, i is not defined. ]
Ans 4. a [ “i” is not in “abcdef”. ]
Ans 5. c [ As the value of i or x isn’t changing, the condition will always evaluate to True. ]
Ans 6. b [ As the value of i or x isn’t changing, the condition will always evaluate to True. ]
Ans 7. b [ The string x is being shortened by one character in each iteration. ]
Ans 8. c [ String x is not being altered and i is in x[:-1]. ]
Ans 9. b [ The string x is being shortened by one character in each iteration. ]
Ans 10. c [ i is not in x[1:] ]
WHILE AND FOR LOOPS – 3 REASION
Ans 1. b [ Changes do not happen in-place, rather a new instance of the string is returned. ]
Ans 2. b [ The instance of the string returned by upper() is being printed. ]
Ans 3. c [ range(str) is not allowed. ]
Ans 4. b [ i takes values 0, 1, 2 and 3. ]
Ans 5. c [ Objects of type int have no attribute upper().]
Ans 6. c [ Objects of type int have no attribute upper().]
Ans 7. a [ Changes do not happen in-place, rather a new instance of the string is returned. ]
Ans 8. c [ Objects of type int aren’t subscriptable. However, if the statement was x[i], an error would not have
been thrown. ]
Ans 9. c [ range() is computed only at the time of entering the loop. ]
Ans 10. d [ abcd a a a is the output as x is modified only after ‘abcd’ has been printed once. ]
WHILE AND FOR LOOPS – 4 REASION
Ans 1. c [ Objects of type int are not iterable. ]
Ans 2. a [ Loops over the keys of the dictionary. ]
Ans 3. d [ Error, objects of type int aren’t iterable. ]
Ans 4. c [ Loops over key, value pairs. ]
Ans 5. b [ Loops over the keys and prints the values. ]
Ans 6. b [ Loops over the values. ]
Ans 7. d [ Causes a KeyError. ]
Ans 8. c [ Objects of type set have no attribute values. ]
Ans 9. a [ Loops over the elements of the set and prints them. ]
Ans 10. c [ Variable x takes the values 0, 1 and 2. set.add() returns None which is printed. ]
Ans 11. b [ range(0) is empty. ]
WHILE AND FOR LOOPS – 5 RESION
Ans 1. c [ Object of type float cannot be interpreted as an integer. ]
Ans 2. b [ range(int(2.0)) is the same as range(2). ]
Ans 3. d [ Error, objects of type float cannot be interpreted as an integer. ]

Page 8 of 9 Computer Science 083 PYTHON pgt.csip.gajedra@gmail.com


MCQ PYTHON WHILE AND FOR LOOPS By Gajendra Sir Mo. No. : 9810301034
Ans 4. d [ OverflowError, cannot convert float infinity to integer. ]
Ans 5. b [ [::-1] reverses the list. ]
Ans 6. b [ ‘ ‘.join(reversed(list(‘abcd’))) reverses a string. ]
Ans 7. b [ [::-1] reverses the string. ]
Ans 8. b [ The string does not have any character to loop over. ]
Ans 9. c [ Variable x is incremented and printed twice. ]
Ans 10. b [ The loop is entered twice. ]

WHILE AND FOR LOOPS – 6 RESION


Ans 1. b [ The else part is executed if control doesn’t break out of the loop. ]
Ans 2. a [ The else part is executed if control doesn’t break out of the loop. ]
Ans 3. a [ The first statement creates a generator object. ]
Ans 4. a [ We can loop over a generator object only once. ]
Ans 5. a [ Variable i takes the value of one character at a time. ]
Ans 6. c [ Variable i takes the value of one word at a time. ]
Ans 7. b [ The value of a[-1] changes in each iteration. ]
Ans 8. a [ The value of a[0] changes in each iteration. Since the first value that it takes is itself, there is no
visible error in the current example. ]
Ans 9. c [ SyntaxError, not in isn’t allowed in for loops. ]
Ans 10. a [ Variable i takes the value of one character at a time]

Page 9 of 9 Computer Science 083 PYTHON pgt.csip.gajedra@gmail.com

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy