From 5269c57765a60b6ce7fde94066a92cd52a3b809b Mon Sep 17 00:00:00 2001 From: Kunal Nagar <160893021+CogitoKunal@users.noreply.github.com> Date: Sat, 26 Oct 2024 10:43:06 +0530 Subject: [PATCH] Create Simple_Stop_Watch.py --- .../Simple_Stop_Watch.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Program's_Contributed_By_Contributors/Simple_Stop_Watch.py diff --git a/Program's_Contributed_By_Contributors/Simple_Stop_Watch.py b/Program's_Contributed_By_Contributors/Simple_Stop_Watch.py new file mode 100644 index 0000000000..1f83c6365d --- /dev/null +++ b/Program's_Contributed_By_Contributors/Simple_Stop_Watch.py @@ -0,0 +1,41 @@ +import time + +print('Press ENTER to begin, Press Ctrl + C to stop') +while True: + try: + input() #For ENTER + starttime = time.time() + print('Started') + except KeyboardInterrupt: + print('Stopped') + endtime = time.time() + print('Total Time:', round(endtime - starttime, 2),'secs') + break +# Press enter to start and stop the watch +""" +import time + +print('Press Enter to begin, Press Enter again to stop') +if input()=='': + starttime = time.time() + print('Started') + while True: + val=input() #For ENTER + if val=='': + print('Stopped') + endtime = time.time() + print('Total Time:', round(endtime - starttime, 2),'secs') + break + +""" + +""" +Output: +Press Enter to begin, Press Enter again to stop + +Started + +Stopped +Total Time: 1.05 secs + +""" \ No newline at end of file