Add try..except to clock and fix str

Change-Id: Ia122da2a8b4ff5caa58d13a42a89392c37de0ea7
This commit is contained in:
Stenio Araujo 2018-02-28 15:08:52 -03:00
parent 6faa9e3e42
commit ee0730a8f6
1 changed files with 7 additions and 4 deletions

View File

@ -29,9 +29,9 @@ class StopWatch:
while True:
text = "{:02}:{:02}:{:02}".format(
self.hours, self.minutes, self.seconds)
print(text, end="r", flush=True)
self.count()
print(text, end="\r", flush=True)
time.sleep(1)
self.count()
def count(self):
"""Increment seconds by one, and increment all the rest"""
@ -50,9 +50,12 @@ class StopWatch:
"Minutes: {}\n"
"Seconds: {}")
print(result.format(self.hours, self.minutes, self.seconds))
return result.format(self.hours, self.minutes, self.seconds)
if __name__ == "__main__":
WATCH = StopWatch()
WATCH.start()
try:
WATCH.start()
except KeyboardInterrupt:
print(WATCH)