What can range really do?
- starting value: what number do you want to start with?
- ending value: the number after the number you want to end with (example: if you type 10 as the ending value, the computer will count until 9)
- increment: How much should it increase by every time it loops? (example: Do you want to count by 1s, 5s, 10s?)
EXAMPLE :
for i in range(1, 8):
print("Day", i)
Increments
We know that this range will start at 0 and continue to 999,999 (which is the number right before the ending value written). The number will increase in increments of 25 each time.
EXAMPLE :
for i in range (0, 1000000, 25):
print(i)
Counting Backward
In this example, we are starting at 10 and counting backward to 0 (because 0 is what comes right before the ending value listed), and counting backward 1 each time.
EXAMPLE :
for i in range(10, -1, -1):
print(i)
Comments
Post a Comment