Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Time:
- max_hours = 23
- max_minutes = 59
- max_seconds = 59
- def __init__(self, hours, minutes, seconds):
- self.hours = hours
- self.minutes = minutes
- self.seconds = seconds
- def set_time(self, hours, minutes, seconds):
- self.hours = hours
- self.minutes = minutes
- self.seconds = seconds
- def get_time(self):
- self.hours = (self.hours + (self.minutes + self.seconds // 60) // 60) % 24
- self.minutes = (self.minutes + self.seconds // 60) % 60
- self.seconds = self.seconds % 60
- return f"{self.hours:02d}:{self.minutes:02d}:{self.seconds:02d}"
- def next_second(self):
- self.seconds += 1
- return self.get_time()
- time = Time(9, 30, 59)
- print(time.next_second())
- time = Time(10, 59, 59)
- print(time.next_second())
- time = Time(23, 59, 59)
- print(time.next_second())
Advertisement
Add Comment
Please, Sign In to add comment