CBSE Class 11 Computer Science
Question 56 of 80
Conditional and Looping Constructs — Question 26
Back to all questions20
22
24
26
28
Below is a detailed explanation of this code:
range(20, 30, 2): This generates a sequence of numbers starting from 20 (inclusive) up to but not including 30 (exclusive), incrementing by 2 each time.
The general form of therangefunction isrange(start, stop, step),where:startis the starting number of the sequence.stopis the endpoint (the number is not included in the sequence).stepspecifies the increment between each number in the sequence.
for i in range(20, 30, 2):: Theforloop iterates over each number generated by therangefunction and assigns it to the variableiduring each iteration.print(i): This prints the current value ofifor each iteration.
Let's list the numbers generated by range(20, 30, 2):
- Start at 20.
- Increment by 2: 20 + 2 = 22.
- Increment by 2: 22 + 2 = 24.
- Increment by 2: 24 + 2 = 26.
- Increment by 2: 26 + 2 = 28.
- The next increment would be 28 + 2 = 30, but 30 is not included as the
stopparameter is exclusive of the value.
Therefore, the sequence of numbers is: 20, 22, 24, 26, 28.