From f1ffc3d688c2671e604998146f8779da8ac67d4c Mon Sep 17 00:00:00 2001 From: Daniel Moix <dwm69@drexel.edu> Date: Wed, 12 Jul 2023 09:15:53 -0400 Subject: [PATCH] Added a working Clock class --- cs172/Lect03/WorkingClock.py | 39 ++++++++++++++++++++++++++++++++++++ cs172/Lect03/old.py | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 cs172/Lect03/WorkingClock.py diff --git a/cs172/Lect03/WorkingClock.py b/cs172/Lect03/WorkingClock.py new file mode 100644 index 0000000..0bc49ef --- /dev/null +++ b/cs172/Lect03/WorkingClock.py @@ -0,0 +1,39 @@ +class Clock: + + def __init__(self): + self.__hours = 12 + self.__minutes = 0 + + def getHours(self): + return self.__hours + + def getMinutes(self): + return self.__minutes + + def getTime(self): + return f"{self.__hours}:{str(self.__minutes).zfill(2)}" + + def setTime(self, newHours, newMinutes): + if newHours <= 12 and newHours >= 1: + self.__hours = newHours + else: + raise Exception("Invalid value for hours") + if newMinutes <= 59 and newMinutes >= 0: + self.__minutes = newMinutes + else: + raise Exception("Invalid value for minutes") + + def addMinute(self): + self.__minutes += 1 + if self.__minutes > 59: + self.__minutes = 0 + self.__hours += 1 + if self.__hours == 13: + self.__hours = 1 + +if __name__ == "__main__": + myClock = Clock() + while True: + print(myClock.getTime()) + myClock.addMinute() + diff --git a/cs172/Lect03/old.py b/cs172/Lect03/old.py index 6853513..1373759 100644 --- a/cs172/Lect03/old.py +++ b/cs172/Lect03/old.py @@ -1,7 +1,7 @@ def main(): print("This code is in the old file") - + s def printHappyFace(): print("😘") -- GitLab