+ 1

for range()

can anyone help with explanation. why answer is 8? for i in range (5): i=i+i print (i)

26th Jul 2018, 2:25 PM
tardigrade
tardigrade - avatar
8 Antworten
+ 2
and what about this? j=0 for z in range (100): j=j+j print (j) output:0 I can't just see difference between this and above example. Plus in cases j=j+1, j=j+2, etc answers respectively are 100, 200 etc. why?
26th Jul 2018, 2:44 PM
tardigrade
tardigrade - avatar
+ 2
anyway thanks, I will review again.
26th Jul 2018, 2:52 PM
tardigrade
tardigrade - avatar
+ 1
i is 0 i is 1 i is 1+1 i is 2+2 i is 3+3 i is 4+4 i is 8! Note: The range() function will not reach 5! It stops one before. This is very important!!
26th Jul 2018, 2:32 PM
Paul Grasser
Paul Grasser - avatar
+ 1
sorry I edited my post. look again please
26th Jul 2018, 2:48 PM
tardigrade
tardigrade - avatar
0
b is 0. B is never changed. You do for j!! do for b in range...
26th Jul 2018, 2:46 PM
Paul Grasser
Paul Grasser - avatar
0
That doesn't output 0.
26th Jul 2018, 2:49 PM
Paul Grasser
Paul Grasser - avatar
0
J will either be 198 or 398 (if you use range(100) or range(200)
26th Jul 2018, 2:51 PM
Paul Grasser
Paul Grasser - avatar
0
ok
26th Jul 2018, 2:52 PM
Paul Grasser
Paul Grasser - avatar