Python

Python

While and For Loops has 45 Questions
What is the output of the following?
x = ['ab', 'cd']
for i in x:
    i.upper()
print(x)

['ab', 'cd']
['AB', 'CD']
[None, None]
none of the mentioned
What is the output of the following?
x = ['ab', 'cd']
for i in x:
    x.append(i.upper())
print(x)

['AB', 'CD']
['ab', 'cd', 'AB', 'CD']
['ab', 'cd']
none of the mentioned
What is the output of the following?
i = 1
while True:
    if i%3 == 0:
        break
    print(i)
    i + = 1

1 2
1 2 3
error
none of the mentioned
What is the output of the following?
i = 5
while True:
    if i%0O11 == 0:
        break
    print(i)
    i += 1

5 6 7 8 9 10
5 6 7 8
5 6
error
What is the output of the following?
i = 5
while True:
    if i%0O9 == 0:
        break
    print(i)
    i += 1

5 6 7 8
5 6 7 8 9
5 6 7 8 9 10 11 12 13 14 15 ....
error
What is the output of the following?
i = 1
while True:
    if i%2 == 0:
        break
    print(i)
    i += 2

1
1 2
1 2 3 4 5 6 ...
1 3 5 7 9 11 ...
What is the output of the following?
i = 2
while True:
    if i%3 == 0:
        break
    print(i)
    i += 2

2 4 6 8 10 ...
2 4
2 3
error
What is the output of the following?
i = 1
while False:
    if i%2 == 0:
        break
    print(i)
    i += 2

1
1 3 5 7 ...
1 2 3 4 ...
none of the mentioned
What is the output of the following?
True = False
while True:
    print(True)
    break

True
False
None
none of the mentioned
What is the output of the following?
i = 0
while i < 5:
    print(i)
    i += 1
    if i == 3:
        break
else:
    print(0)

0 1 2 0
0 1 2
error
none of the mentioned
What is the output of the following?
x = "abcdef"
i = "a"
while i in x:
    print(i, end = " ")

no output
i i i i i i ...
a a a a a a ...
a b c d e f
What is the output of the following?
x = "abcdef"
i = "a"
while i in x:
    print('i', end = " ")

no output
i i i i i i ...
a a a a a a ...
a b c d e f
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 a a a a
a a a a a a ...
a
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
no output
error
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
no output
error
What is the output of the following?
x = 'abcd'
for i in x:
    print(i)
    x.upper()

a B C D
a b c d
A B C D
error
What is the output of the following?
x = 'abcd'
for i in x:
    print(i.upper())

a b c d
A B C D
a B C D
error
What is the output of the following?
x = 'abcd'
for i in range(x):
    print(i)

a b c d
0 1 2 3
error
none of the mentioned
What is the output of the following?
x = 'abcd'
for i in range(len(x)):
    print(i.upper())

a b c d
0 1 2 3
error
none of the mentioned
What is the output of the following?
x = 'abcd'
for i in range(len(x)):
    i.upper()
print (x)

a b c d
0 1 2 3
error
none of the mentioned
What is the output of the following?
x = 'abcd'
for i in range(len(x)):
    x[i].upper()
print (x)

abcd
ABCD
error
none of the mentioned
What is the output of the following?
x = 'abcd'
for i in range(len(x)):
    i[x].upper()
print (x)

abcd
ABCD
error
none of the mentioned
What is the output of the following?
x = 'abcd'
for i in range(len(x)):
    x = 'a'
    print(x)

a
abcd abcd abcd
a a a a
none of the mentioned
What is the output of the following?
x = 'abcd'
for i in range(len(x)):
    print(x)
    x = 'a'

a
abcd abcd abcd abcd
a a a a
none of the mentioned
What is the output of the following?
x = 123
for i in x:
    print(i)

1 2 3
123
error
none of the mentioned
What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for i in d:
    print(i)

0 1 2
a b c
0 a 1 b 2 c
none of the mentioned
What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for x, y in d.items():
    print(x, y)


0 1 2
a b c
0 a 1 b 2 c
none of the mentioned
What is the output of the following?
for i in range(2.0):
    print(i)

0.0 1.0
0 1
error
none of the mentioned
What is the output of the following?
for i in range(int(2.0)):
    print(i)

0.0 1.0
0 1
error
none of the mentioned
What is the output of the following?
for i in range(float('inf')):
    print (i)

0.0 0.1 0.2 0.3 ...
0 1 2 3 ...
0.0 1.0 2.0 3.0 ...
none of the mentioned
What is the output of the following?
for i in [1, 2, 3, 4][::-1]:
    print (i)

1 2 3 4
4 3 2 1
error
none of the mentioned
What is the output of the following?
for i in ''.join(reversed(list('abcd'))):
    print (i)

a b c d
d c b a
error
none of the mentioned
What is the output of the following?
for i in 'abcd'[::-1]:
    print (i)

a b c d
d c b a
error
none of the mentioned
What is the output of the following?
for i in '':
    print (i)

None
(nothing is printed)
error
none of the mentioned
What is the output of the following?
x = 2
for i in range(x):
    x += 1
    print (x)

0 1 2 3 4 ...
0 1
3 4
0 1 2 3
What is the output of the following?
x = 2
for i in range(x):
    x -= 2
    print (x)

0 1 2 3 4 ...
0 -2
0
error
What is the output of the following?
for i in range(10):
    if i == 5:
        break
    else:
        print(i)
else:
    print("Here")

0 1 2 3 4 Here
0 1 2 3 4 5 Here
0 1 2 3 4
1 2 3 4 5
What is the output of the following?
for i in range(5):
    if i == 5:
        break
    else:
        print(i)
else:
    print("Here")

0 1 2 3 4 Here
0 1 2 3 4 5 Here
0 1 2 3 4
1 2 3 4 5
What is the output of the following?
x = (i for i in range(3))
for i in x:
    print(i)

0 1 2
error
0 1 2 0 1 2
none of the mentioned
What is the output of the following?
string = "my name is x"
for i in string:
    print (i, end=", ")

m, y, , n, a, m, e, , i, s, , x,
m, y, , n, a, m, e, , i, s, , x
my, name, is, x,
error
What is the output of the following?
string = "my name is x"
for i in string.split():
    print (i, end=", ")

m, y, , n, a, m, e, , i, s, , x,
m, y, , n, a, m, e, , i, s, , x
my, name, is, x,
error
What is the output of the following?
a = [0, 1, 2, 3]
for a[-1] in a:
    print(a[-1])

0 1 2 3
0 1 2 2
3 3 3 3
error
What is the output of the following?
a = [0, 1, 2, 3]
for a[0] in a:
    print(a[0])

0 1 2 3
0 1 2 2
3 3 3 3
error
What is the output of the following?
a = [0, 1, 2, 3]
i = -2
for i not in a:
    print(i)
    i += 1

-2 -1
0
error
none of the mentioned
What is the output of the following?
string = "my name is x"
for i in ' '.join(string.split()):
    print (i, end=", ")

m, y, , n, a, m, e, , i, s, , x,
m, y, , n, a, m, e, , i, s, , x
my, name, is, x,
error