class Time(object): """represents the time of day. attributes: hour, minute, second"""
time = Time() time.hour = 11 time.minutes = 59 time.second = 30
def add_time(t1, t2): sum = Time() sum.hour = t1.hour + t2.hour sum.minutes = t1.minutes + t2.minutes sum.second = t1.second + t2.second return sum
time1 = Time() time1.hour = 11 time1.minutes = 59 time1.second = 30 time2 = Time() time2.hour = 1 time2.minutes = 12 time2.second = 15 def print_time(t): print('{}:{}:{}'.format(t.hour, t.minutes, t.second)) def add_time(t1, t2): sum = Time() sum.hour = t1.hour + t2.hour sum.minutes = t1.minutes + t2.minutes sum.second = t1.second + t2.second return sum t = add_time(time1, time2) print_time(t) # 12:71:45
def add_time(t1, t2): sum = Time() sum.hour = t1.hour + t2.hour sum.minutes = t1.minutes + t2.minutes sum.second = t1.second + t2.second if sum.second >= 60: sum.second -= 60 sum.minutes += 1 if sum.minutes >= 60: sum.minutes -= 60 sum.hour += 1 return sum
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
Time
Pure functions
Recent Posts
Archive Posts
Tags