class Time: def __init__(self, hour, min): self.hour = hour self.min = min def __str__(self): """overloading the str operator (STRing)""" return f"[ {self.hour:2}:{self.min:02} ]" def __gt__(self, other): """overloading the GreaterThan operator""" selfminutes = self.hour * 60 + self.min otherminutes = other.hour * 60 + other.min return selfminutes > otherminutes class TimeUK(Time): """Derived (or inherited class)""" def __str__(self): """overloading the str operator (STRing)""" if self.hour < 12: ampm = "am" else: ampm = "pm" return f"[ {self.hour%12:2}:{self.min:02} {ampm}]" if __name__ == "__main__": t3 = TimeUK(15, 45) print(f"TimeUK object = {t3}") t4 = Time(16, 15) print(f"Time object = {t4}") print("compare t3 and t4: ") if t3 > t4: print("t3 is greater than t4") else: print("t3 is not greater than t4")