8000 added · techbire/python-project@68fcf98 · GitHub
[go: up one dir, main page]

Skip to content

Commit 68fcf98

Browse files
authored
added
1 parent bab1fc6 commit 68fcf98

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Stopwatch/main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import time
2+
3+
def stopwatch():
4+
input("Press Enter to start the stopwatch.")
5+
start_time = time.time()
6+
7+
try:
8+
while True:
9+
elapsed_time = time.time() - start_time
10+
mins, secs = divmod(elapsed_time, 60)
11+
hours, mins = divmod(mins, 60)
12+
time_format = "{:02}:{:02}:{:02}".format(int(hours), int(mins), int(secs))
13+
print("\rTime elapsed: {}".format(time_format), end="")
14+
time.sleep(1)
15+
16+
except KeyboardInterrupt:
17+
pass # Catch Ctrl+C to stop the stopwatch
18+
19+
finally:
20+
print("\nStopwatch stopped. Total time elapsed: {}".format(time_format))
21+
22+
stopwatch()

0 commit comments

Comments
 (0)
0