Computer Science
Find the output of the following:
for i in range(20, 30, 2):
print (i)
- 1.
21
22
23
24
25
- 2.
21
23
25
27
29
3. SyntaxError
4.
20
22
24
26
28
Python Control Flow
1 Like
Answer
20
22
24
26
28
Reason — The code uses a for
loop with range(20, 30, 2)
, generating numbers from 20 to 28 with a step of 2. It iterates through these values, printing each number (20, 22, 24, 26, 28) on a new line.
Answered By
2 Likes
Related Questions
Kritika wants to divide a number and store the result without decimal places into an integer variable. Suggest an appropriate operator from the following:
- /
- %
- //
- Both (a) and (b)
Which of the following methods splits the string at the first occurrence of separator and returns a tuple containing three items?
- index()
- partition()
- split()
- count()
Which of the following functions will return the first three characters of a string named 's'?
- s[3:]
- s[:3]
- s[-3:]
- s[:-3]
Observe the given code and select the appropriate output.
Tuple given: tup1 = (10, 20, 30, 40, 50, 60, 70, 80, 90)
What will be the output of: print(tup1[3:7:2])
- (40, 50, 60, 70, 80)
- (40, 50, 60, 70)
- (40, 60)
- Error