From 75a42ec54dbf721caa659ddf02c1f46fc2cb4bef Mon Sep 17 00:00:00 2001 From: mlot Date: Fri, 6 Jun 2025 13:40:57 -0400 Subject: initial commit for archiving --- Chap15PracPrettifiedStopwatch.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Chap15PracPrettifiedStopwatch.py (limited to 'Chap15PracPrettifiedStopwatch.py') diff --git a/Chap15PracPrettifiedStopwatch.py b/Chap15PracPrettifiedStopwatch.py new file mode 100644 index 0000000..28a54b3 --- /dev/null +++ b/Chap15PracPrettifiedStopwatch.py @@ -0,0 +1,40 @@ +#! python3 +#! /usr/bin/env python3 + +# Chapter 15 Practice Prettified Stopwatch +# Simple Stop Watch Program + +# NOTE: Writing output to data text file rather than use pyperclip module. +# Then file can be attached to email or copied as needed. And a +# separate module outside the standard library is not required. + +import time +import datetime + +dataFile = open('stopWatchData.txt', 'a') + +dt = datetime.datetime.now() +timeStamp = dt.strftime('\n%m/%d/%Y %H:%M\n') +dataFile.write(timeStamp) + +print('Press ENTER to begin. Afterwards, press ENTER to click the stopwatch.') +print('Press CTRL-C to quit.') +input() +print('Started...') +startTime = time.time() +lastTime = startTime +lapNum = 1 + +try: + while True: + input() + lapTime = round(time.time() - lastTime, 2) + totalTime = round(time.time() - startTime, 2) + print('Lap #%s: %s (%s)' % (str(lapNum).ljust(2), str(totalTime).rjust(4), str(lapTime).rjust(5)), end='') + dataFile.write('Lap #%s: %s (%s)\n' % (str(lapNum).ljust(2), str(totalTime).rjust(4), str(lapTime).rjust(5))) + lapNum += 1 + lastTime = time.time() +except KeyboardInterrupt: + print('\nDone.') + +dataFile.close() -- cgit