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

Question: Write a boolean function after that takes two Time objects, t1 and t2,

ID: 3619802 • Letter: Q

Question

Question: 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.
--
The reading for this question is posted below:
---
Time:

As another example of a user-defined type, we’ll define a class called Time that
records the time of day. The class definition looks like this:
class Time:
   pass
We can create a new Time object and assign attributes for hours, minutes, and
seconds:
time = Time()
time.hours = 11
time.minutes = 59
time.seconds = 30
The state diagram for the Time object looks like this:

Explanation / Answer

class time:
   hours = 12;
   minutes = 00;
   seconds = 00;

def compareTimes(t1,t2):
   if t1.hours > t2.hours:
       return False;
   elif t1.hours < t2.hours:
       return True;
   else:
       if t1.minutes > t2.minutes:
           return False;
       elif t1.minutes < t2.minutes:
           return True;
       else:
           if t1.seconds > t2.seconds:
               return False;
           elif t1.seconds < t2.seconds:
               return True;


t2= time();
t1= time();
t1.hours = 2
t2.minutes=10
t1.minutes = 11;
t1.seconds = 11;
t2.hours = 1;
t2.seconds = 34;
print compareTimes(t1,t2);

raw_input();
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote