Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Clock:
- def __init__(self, hrsIn, minsIn, secsIn):
- self.hours = hrsIn
- self.minutes = minsIn
- self.seconds = secsIn
- def SetTime(self, newHrsIn, newMinsIn, newSecsIn):
- self.hours = newHrsIn
- self.minutes = newMinsIn
- self.seconds = newSecsIn
- def GetHours(self):
- return self.hours
- def GetMinutes(self):
- return self.minutes
- def GetSeconds(self):
- return self.seconds
- def DisplayTime24(self):
- print("The time is", format(self.hours, '2d'), ": ", end="")
- if (self.minutes < 10):
- print("0",end="")
- print(self.minutes, ": ", end="")
- if (self.seconds < 10):
- print("0",end="")
- print(self.seconds)
- def DisplayTime12(self):
- print("The time is ", end="")
- if (self.hours <= 12):
- if (self.hours == 0):
- print("12 : ", end= "")
- else:
- print(self.hours, ": ", end="")
- if (self.hours == 12):
- tag = "PM"
- else:
- tag = "AM"
- else:
- print(self.hours - 12, ": ", end="")
- tag = "PM"
- if(self.minutes < 10):
- print("0", end="")
- print(self.minutes, ": ", end="")
- if(self.seconds < 10):
- print("0", end="")
- print(self.seconds, tag)
- def IncrementClock(self):
- self.seconds = self.seconds + 1
- if (self.seconds == 60):
- self.seconds = 0
- self.minutes = self.minutes + 1
- if (self.minutes == 60):
- self.minutes = 0
- self.hours = self.hours + 1
- if (self.hours == 23):
- self.hours = 0
- def main():
- myClock = Clock(0,0,0)
- myClock.DisplayTime12()
- myClock.DisplayTime24()
- print()
- myClock.SetTime(22,30,5)
- myClock.DisplayTime12()
- myClock.DisplayTime24()
- print()
- myClock = Clock(11,59,59)
- myClock.DisplayTime12()
- myClock.DisplayTime24()
- print()
- myClock.IncrementClock()
- myClock.DisplayTime12()
- myClock.DisplayTime24()
- print()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement