Consider the following code segment:
for i in range(2,4):
print (i)
What value(s) are printed when it executes ?
Answers
Answered by
1
OUTPUT:-
2
3
Explanation:
By default, in python the value of I increses by 1.
Given initial value of I is 2 and the limit is 4.
Note:-
Here the loop will start from 2 and will work upto 3 that is...4 is not included in it
Therefore
- When I is 2, Output will be 2 and the cursor will got to the next line and the value of I increases.
- When the value increases the control checks if the value of I is less then 4...True....it will print 3.....Now the value of I is 4
- 4<4 ... Condition False....So loop will terminate
Therefore,
The correct output is:-
2
3
Similar questions
English,
1 month ago
Math,
1 month ago
Computer Science,
2 months ago
Social Sciences,
2 months ago
Science,
7 months ago
Math,
7 months ago