In [10]:
class Time:
"""Represents the time of day.
attributes: hour, minute, second
"""
In [11]:
time = Time()
time.hour = 11
time.minute = 59
time.second = 30
In [12]:
def time_to_s(time):
return("{:02}:{:02}:{:02}".format(time.hour, time.minute, time.second))
In [13]:
def print_time(time):
print(time_to_s(time))
In [14]:
print_time(time)
In [15]:
import numpy as np
t2 = Time()
t2.hour = np.random.randint(0, high=24)
t2.minute = np.random.randint(0, high=60)
t2.second = np.random.randint(0, high=60)
print_time(t2)
In [16]:
def to_seconds(t):
return 3600 * t.hour + 60 * t.minute + t.second
In [17]:
def is_after(t1, t2):
return to_seconds(t1) > to_seconds(t2)
In [18]:
print("{} is {} {}".format(time_to_s(time), "after" if is_after(time, t2) else "before", time_to_s(t2)))