Reputation: 13
I am trying to update the start 'i' index to the end 'i' index after every iteration. How do I go about this? So printing it would give me (1, 11), (11, 21), etc.. Thanks!
for i in range(1, 100):
print(i, i+10)
Upvotes: 0
Views: 837
Reputation: 341
Another method I'd like to suggest:
for i in range(10): # So i goes from 0 to 9
print( 10*i+1 , 10*(i+1)+1 )
It prints:
1 11
11 21
21 31
31 41
41 51
51 61
61 71
71 81
81 91
91 101
Upvotes: 0
Reputation: 314
The code you need is this:
for i in range(1, 100, 10):
print(i, i+10)
Upvotes: 0
Reputation: 11486
You can use the step
argument of range
:
for i in range(1, 100, 10):
print(i, i+10)
outputs
1 11
11 21
21 31
31 41
41 51
51 61
61 71
71 81
81 91
91 101
Upvotes: 6