Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6779d27

Browse files
Create countdown_clock_and_timer.py
1 parent 31f154a commit 6779d27

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# import modules like 'os' and 'time'
2+
import os
3+
import time
4+
5+
os.system('clear')
6+
7+
# using ctime() to show present time
8+
times = time.ctime()
9+
print("\nCurrent Time: ",times)
10+
11+
print("\n Welcome to CountdownTimer!\n\n Let's set up the countdown timer...\n")
12+
13+
# User input for the timer
14+
hours = int(input(" How many hours? "))
15+
minutes = int(input(" How many minutes? "))
16+
seconds = int(input(" How many seconds? "))
17+
18+
# To display message when the given value is not a number
19+
if hours or minutes or seconds == "":
20+
print("\n Invalid entry. You must enter a number.")
21+
22+
# Conversion of hours amd minutes into seconds
23+
hrsToSec = (hours * 60) * 60
24+
mnsToSec = (minutes * 60)
25+
seconds = seconds
26+
27+
seconds = hrsToSec + mnsToSec + seconds
28+
print("\n Timer has been set for "+str(seconds) + " seconds.")
29+
30+
# Loop for displaying the timer
31+
32+
for i in range(seconds, -1, -1):
33+
displayHours = int(seconds / 3600)
34+
displayMinutes = int(seconds / 60)
35+
if displayMinutes >= 60:
36+
displayMinutes = displayMinutes - (displayHours * 60)
37+
else:
38+
displayMinutes = displayMinutes
39+
displaySeconds = int(seconds % 60)
40+
print("\n Your time remaining is: {}:{}:{}".format(str(displayHours).zfill(2), str(displayMinutes).zfill(2), str(displaySeconds).zfill(2)))
41+
seconds -= 1
42+
time.sleep(1) # delays in the excution of a program for 1 second
43+
44+
print("\n Time is over.")
45+
46+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /