Iterations Output#
Find the output of the following code.
Please don’t run the code before giving your answer.
Question-1#
for i in range(13,29,5):
print(i)
Solution
13
18
23
28
Question-2#
for i in range(13,1,-3):
print(i)
Solution
13
10
7
4
Question-3#
n = 5
while n >= -3:
print(n)
n -= 2
Solution
5
3
1
-1
-3
Question-4#
for i in 'TEXAS':
print(i, end='-')
Solution
T-E-X-A-S-
Question-5#
country = 'Germany'
for i in range(2,len(country)):
print(country[:i])
Solution
Ge
Ger
Germ
Germa
German
Question-6#
text = 'abcdefghijklmnopqrstuwxyz'
for i in range(2,9,3):
print(text[i])
Solution
c
f
i
Question-7#
text = 'abcdefghijklmnopqrstuwxyz'
for i in text:
if i >= 'w':
print(i)
Solution
w
x
y
z
Question-8#
while True:
print(1)
if 5:
break
Solution
1
Question-9#
x = 16
while x >= 1:
print(x)
x /= 2
print('DONE!')
Solution
16
8.0
4.0
2.0
1.0
DONE!
Question-10#
total = 0
for i in range(2, 45, 10):
total += i
print(total)
Solution
110
Question-11#
for i in range(5):
for j in range(6,10):
print(j, end='')
print()
Solution
6789
6789
6789
6789
6789
Question-12#
for i in range(5):
for j in range(i,3):
print(j, end='')
print()
Solution
012
12
2
Question-13#
for i in range(5,10):
for j in range(4,i):
print(j, end='')
print()
Solution
4
45
456
4567
45678
Question-14#
text = 'abcdefghijklmnopqrstuwxyz'
for i in 'text':
if i >= 'w':
print(i)
Solution
x