Add try..except to clock and fix str
Change-Id: Ia122da2a8b4ff5caa58d13a42a89392c37de0ea7
This commit is contained in:
parent
6faa9e3e42
commit
ee0730a8f6
11
_clock.py
11
_clock.py
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue