An odometer is the meter in a car that registers how many miles (or kilometers) the car has traveled in its lifetime. It begins at
000000
and every mile that it travels, the counter ticks up by one:
000001
… then
000002
and so on.
Write a program odometer.py
that uses 4 nested loops to print out a four-digit odometer. Use one separate loop for each digit in the odometer:
0 0 0 0
^ ^ ^ ^
| | | |
i j k l
It may be helpful for you to print out the numbers using print formatting:
print("{0:1d}{1:1d}{2:1d}{3:1d}".format(i,j,k,l))
You may wish to slow the odometer down a little by using the time
module and having it sleep between ticks:
import time
.
.
.
time.sleep(0.2) # sleeps for 0.2 seconds
You might also want to clear the screen between each tick:
import os
.
.
.
os.system("clear") # on Apple machine