Counting Up and Down โณ
range() can take more than one number, and that's when it gets powerful.
Two numbers = start and stop:
for i in range(1, 6):
print(i) # โ 1 2 3 4 5
It starts at 1 and stops just before 6. Python always stops before the second number โ a bit rude, but you get used to it.
Three numbers = start, stop, and step:
for i in range(10, 0, -1):
print(i) # โ 10 9 8 7 6 5 4 3 2 1
That -1 is the step โ instead of going up by one, it goes down by
one. Start at 10, stop just before 0, subtract 1 each turn. Countdown! ๐
Your mission
- Use a loop to print the numbers 1 to 10, going up
- Use a second loop to count back down from 10 to 1
- After the countdown, print a big celebration message
Your code
Press โถ Run to see what your code does!