Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( Python ) Write a Boolean function between that takes two MyTime objects, t 1 and t 2 , as arguments, and returns True if

(Python)Write a Boolean function between that takes two MyTime objects, t1 and t2, as arguments, and returns True if the invoking object falls between
the two times. Assume t1<= t2, and make the test closed at the lower
bound and open at the upper bound, i.e. return True if t1<= obj < t2.
Turn the above function into a method in the MyTime class. Code to modify class MyTime:
def __init__(self, hrs=0, mins=0, secs=0):
if hrs<0:
hrs=abs(hrs)
if mins<0:
mins=abs(mins)
if secs<0:
secs=abs(secs)
t_secs = hrs*3600+ mins*60+ secs
self.hrs = t_secs //3600 # Split in h, m, s
left_over_secs = t_secs %3600
self.mins = left_over_secs //60
self.secs = left_over_secs %60
print (t_secs)
def __str__(self):
return "{0}:{1}:{2}".format(self.hrs,self.mins,self.secs)
def __lt__(self,t2):
if self.hrs=t2.hrs and self.mins>=t2.mins and self.secs>=t2.secs:
return True
else:
return False
def __ne__(self,t2):
if self.hrs!=t2.hrs or self.mins!=t2.mins or self.secs!=t2.secs:
return True
else:
return False
def __add__(self,t2):
h=self.hrs+t2.hrs
m=self.mins+t2.mins
s=self.secs+t2.secs
while s>59:
s-=60
m+=1
while m>59:
m-=60
h+=1
sum_t=MyTime(h,m,s)
return sum_t

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions