I want the number be like:
10
100
1000
10000
100000
for i in range(100, 100000+1, x)
what can I do for x, so the number will increment by power of 10
I know it will be easier to using the while loop, but I am not allow to use it ><




Posted 18 October 2012 - 07:02 PM
for i in range(100, 100000+1, x)
Posted 18 October 2012 - 08:09 PM
Posted 18 October 2012 - 08:50 PM
atraub, on 18 October 2012 - 08:09 PM, said:
for i in range(100, 10000000+1, 10**10)
Posted 19 October 2012 - 07:56 AM
for i in range(100, 10000000+1, 10**10) for each value i, starting from 100, going all the way to 10000000+1, and counting by 10000000000
>>> for i in range(10):
print(i)
and the interpreter would output0 1 2 3 4 5 6 7 8 9Notice that it starts from 0 and goes to 9. That's good, but what if I wanted to do 1-10. I basically have two options... I can either do print(i+1) or I can adjust my for loop a little.
>>> for i in range(1,11):
print(i)
and the interpreter would output1 2 3 4 5 6 7 8 9 10Notice that I gave range 2 parameters, a start value and an end value. In the code you used, you provided 3 values. When there's a third value, it's called a "step" or an "increment" i.e. instead of counting by 1's, we can count by some other value. Let's say I only wanted the odd numbers from 1 to 10. I would write:
>>> for i in range(1,11,2):
print(i)
and the interpreter would output1 3 5 7 9
This post has been edited by atraub: 19 October 2012 - 02:11 PM
