How many loops will the following for loop have?
for i in range(1, 5, 2):
print(i, end=" ")
I know that the output is "1 3", but I'm not exactly certain how it goes through, if it loops for each. My gut wants to say 2 loops.
1, skip 2
3, skip 4 and reach end of range.
Is this correct thinking?
range()is the amount that's added to each element to get the next one. So start with1, next is1+2, next is1+2+2, and so on until you reach 5 or more.ceil((5-1)/2) == 2