Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a function printTime that takes a Time object as an argument and prints it

ID: 3620030 • Letter: W

Question

write a function printTime that takes a Time object
as an argument and prints it in the form hours:minutes:seconds.

then write a boolean function AFTER that takes two
Time objects, t1 and t2, as arguments, and returns True if t1 follows
t2 chronologically and False otherwise.

Explanation / Answer

Dear.. Function for printTime: class Time: pass time = Time() time.hours = 11 time.minutes = 59 time.seconds = 30 def printTime(time): print str(time.hours) + ":" + str(time.minutes) + ":" + str(time.seconds) def after(TRUE, FALSE): if TRUE.hour > FALSE.hour: return 1 if TRUE.hour FALSE.minute: return 1 if TRUE.minute FALSE.second: return 1 return 0 def addTime(t1, t2): sum = Time() sum.hours = t1.hours + t2.hours sum.minutes = t1.minutes + t2.minutes sum.seconds = t1.seconds + t2.seconds if sum.seconds >= 60: sum.seconds = sum.seconds - 60 sum.minutes = sum.minutes + 1 if sum.minutes >= 60: sum.minutes = sum.minutes - 60 sum.hours = sum.hours + 1 return sum