piouser09
piouser09

Reputation: 13

Increment index in for loop

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

Answers (3)

Green05
Green05

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

Faheem Anis
Faheem Anis

Reputation: 314

The code you need is this:

for i in range(1, 100, 10):
    print(i, i+10)

Upvotes: 0

enzo
enzo

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

Related Questions