PYTHON
[SUBJECT CODE: 2180711]
CH-2 LOOPS
Topics Covers:-
- Functions and scoping
- Specifications
- Recursion
- Global variables
- Modules
- Files
- System Functions and Parameters
- loops
1.What will be the output of the following Python code?
i =1
while True:
if i%7 ==0O7:
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
2.What will be the output of the following Python code?
i =5
whileTrue:
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
3.What will be the output of the following Python code?
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
4.What will be the output of the following Python code?
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
5.What will be the output of the following Python code?
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
6.What will be the output of the following Python code?
True = False
while True:
print(True)
break
a) True
b) False
c) None
d) none of the mentioned
7.What will be the output of the following Python code?
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
8.What will be the output of the following Python code?
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
d) error
9.What will be the output of the following Python code?
x = "abcdef"
i = "i"
while i in x:
print(i,end=" ")
a)nooutput
b)iiiiii…
c)abcdef
d)abcdef
10.What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
x = x[:-1]
print(i,end = " ")
b) a a a a a a
c) a a a a a
d) none of the mentioned
11.What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
x = x[1:]
print(i,end = " ")
b) a
c) no output
d) error
12.What will be the output of the following Python code?
x = 'abcd'
for i in x:
print(i.upper())
b) A B C D
c) a B C D
d) error
13.What will be the output of the following Python code?
x = 'abcd'
for i in range(len(x)):
print(i)
b) 0 1 2 3
c) error
d) 1 2 3 4
14.What will be the output of the following Python code snippet?
x = 'abcd'
for i in range(len(x)):
i.upper()
print(x)
b) 0 1 2 3
c) error
d) none of the mentioned
15.What will be the output of the following Python code?
for i in range(2.0):
print(i)
a) 0.0 1.0
b) 0 1
c) error
d) none of the mentioned
16.What will be the output of the following Python code?
for i in range(int(2.0)):
print(i)
a) 0.0 1.0
b) 0 1
c) error
d) none of the mentioned
17.What will be the output of the following Python code?
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
18.What will be the output of the following Python code snippet?
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
19.What will be the output of the following Python code snippet?
for i in 'abcd'[::-1]:
print(i)
a) a b c d
b) d c b a
c) error
d) none of the mentioned
20.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
21.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
22.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
23.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) 0 1 2
b) error
c) 0 1 2 0 1 2
d) none of the mentioned
24.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
25.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

0 Comments:
Post a Comment