class Time: def __init__(self, hour, min): self.hour = hour self.min = min def print24h(self): print("{:2}:{:2}".format(self.hour, self.min)) def print12h(self): if self.hour < 12: ampm = "am" else: ampm = "pm" print("{:2}:{:2} {}".format(self.hour % 12, self.min, ampm)) if __name__ == "__main__": t = Time(15, 45) print("print as 24h: "), t.print24h() print("print as 12h: "), t.print12h() print("These are attributes of the time object t:") print(dir(t)) print("The time is %d hours and %d minutes." % (t.hour, t.min))