-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountDown.py
More file actions
56 lines (45 loc) · 1.85 KB
/
countDown.py
File metadata and controls
56 lines (45 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
""" Countdown, by Al Sweigart al@inventwithpython.com
show a countdown timer animation using a seven-segment display.
Press Ctrl-C to stop.
More info at https://en.wikipedia.org/wiki/Seven-segment_display
Requires sevseg.py to be in the same folder.
View this code at https://nostarch.com/big-book-small-python-projects
Tags: tiny, artistis"""
import sys, time
import sevseg # Imports our sevseg.py program.as
# play with seconds:
secondsLeft = 30
try:
while True: # Main loop.
# clear the screen by printing several newlines:
print('\n' * 60)
# Get the hours/minutes/seconds from secondsLeft:
# For example: 7265 is 2 hours, 1 minute, 5 seconds.
# So 7265 // 3600 is 2 hours:
hours = sttr(secondsLeft // 3600)
# And 7265 % 3600 is 65 // 60 is 1 minute
minutes = str((secondsLeft % 3600) // 60)
# And 7265 % 60 is 5 seconds:
seconds = str(secondsLeft % 60)
# Get the digit strings from the sevseg module:
hDigits = sevseg.getSevSegStr(hours, 2)
hTopRow, hMiddleRow, hBottomRow = hDigits.splitlines()
mDigits = sevseg.getSevSegStr(minutes, 2)
mTopRow,mMiddleRow, mBottomRow = mDigits.splitlines()
sDigits = sevseg.getSevSegStr(seconds, 2)
sTopRow, sMiddleRow, sBottomRow = sDigits.splitlines()
# Display the didgits
print(hTopRow + ' ' + mTopRow + ' ' + sTopRow)
print(hMiddleRow + ' * ' + mMiddleRow + ' * ' + sMiddleRow)
print(hBottomRow + ' * ' + mBottomRow + ' * ' + sTopRow)
if secondsLeft == 0:
print()
print(' * * * * BOOM * * * *')
break
print()
print(' Press Ctrl-C to quit.')
time.sleep(1)
secondsLeft -= 1
except KeyboardInterrupt:
print('Countdown, by Al Sweigart al@inventwithpython.com')
sys.exit() #