viligen

time

Feb 25th, 2022
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. class Time:
  2.     max_hours = 23
  3.     max_minutes = 59
  4.     max_seconds = 59
  5.  
  6.     def __init__(self, hours, minutes, seconds):
  7.         self.hours = hours
  8.         self.minutes = minutes
  9.         self.seconds = seconds
  10.  
  11.     def set_time(self, hours, minutes, seconds):
  12.         self.hours = hours
  13.         self.minutes = minutes
  14.         self.seconds = seconds
  15.  
  16.     def get_time(self):
  17.         self.hours = (self.hours + (self.minutes + self.seconds // 60) // 60) % 24
  18.         self.minutes = (self.minutes + self.seconds // 60) % 60
  19.         self.seconds = self.seconds % 60
  20.         return f"{self.hours:02d}:{self.minutes:02d}:{self.seconds:02d}"
  21.  
  22.     def next_second(self):
  23.         self.seconds += 1
  24.         return self.get_time()
  25.  
  26.  
  27. time = Time(9, 30, 59)
  28. print(time.next_second())
  29. time = Time(10, 59, 59)
  30. print(time.next_second())
  31. time = Time(23, 59, 59)
  32. print(time.next_second())
  33.  
Advertisement
Add Comment
Please, Sign In to add comment