Skip to content

Commit 60eac8a

Browse files
committed
countdown timer
1 parent e2580a0 commit 60eac8a

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

days/01-03-datetimes/code/datetime_date.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636

3737
# We need to use != & == rather than is / is not for comparison. Sorry for the mistake in the video.
3838
if christmas != today_date:
39-
print("Sorry there are still " + str((christmas - today_date).days) + " until Christmas!")
39+
print(
40+
"Sorry there are still "
41+
+ str((christmas - today_date).days)
42+
+ " until Christmas!"
43+
)
4044
else:
4145
print("Yay it's Christmas!")

days/01-03-datetimes/code/datetime_timedelta.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
t = timedelta(days=4, hours=10)
77

88
t.days
9-
#4
9+
# 4
1010

1111
t.seconds
12-
#36000
12+
# 36000
1313

14-
t.hours
15-
#Traceback (most recent call last):
16-
#File "<pyshell#119>", line 1, in <module> t.hours
17-
#AttributeError: 'datetime.timedelta' object has no attribute 'hours'
14+
# t.hours
15+
# Traceback (most recent call last):
16+
# File "<pyshell#119>", line 1, in <module> t.hours
17+
# AttributeError: 'datetime.timedelta' object has no attribute 'hours'
1818

1919
t.seconds / 60 / 60
20-
#10.0
20+
# 10.0
2121

2222
t.seconds / 3600
23-
#10.0
23+
# 10.0
2424

2525

2626
#########
@@ -30,10 +30,10 @@
3030
today = datetime.today()
3131

3232
today
33-
#datetime.datetime(2018, 2, 19, 14, 55, 19, 197404
33+
# datetime.datetime(2018, 2, 19, 14, 55, 19, 197404
3434

3535
today + eta
36-
#datetime.datetime(2018, 2, 19, 20, 55, 19, 197404)
36+
# datetime.datetime(2018, 2, 19, 20, 55, 19, 197404)
3737

3838
str(today + eta)
3939
#'2018-02-19 20:55:19.197404'
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from datetime import datetime
2+
import numpy as np
3+
import time
4+
5+
LAST_DAY_OF_SCHOOL = datetime(2021, 6, 10, 11, 50, 0, 0)
6+
7+
def total_countdown():
8+
event_delta = LAST_DAY_OF_SCHOOL - datetime.now()
9+
while (event_delta.days + event_delta.seconds) > 0:
10+
hours, remaining_delta = divmod(event_delta.seconds, 3600)
11+
mins, secs = divmod(remaining_delta, 60)
12+
timer = f"\t{event_delta.days:02d} days {hours:02d} hours {mins:02d} minutes {secs:02d} seconds"
13+
print(timer, end="\r")
14+
time.sleep(1)
15+
event_delta = LAST_DAY_OF_SCHOOL - datetime.now()
16+
17+
print("School's out for summer!")
18+
19+
20+
def school_days():
21+
today = datetime.now()
22+
print(f"\tThere are {np.busday_count(today.date(), LAST_DAY_OF_SCHOOL.date()) -1} school days left in the 2020-2021 school year.")
23+
pass
24+
25+
26+
print()
27+
school_days()
28+
print()
29+
print("\tTime until school is out for summer 2021:", end="\n\n")
30+
total_countdown()
31+
32+

0 commit comments

Comments
 (0)