8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bab1fc6 commit 68fcf98Copy full SHA for 68fcf98
Stopwatch/main.py
@@ -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