Question: class TimeType: def _ _ init _ _ ( self , hr = 0 , min = 0 , sec = 0 ) : self.hr

class TimeType:
def __init__(self, hr=0, min=0, sec=0):
self.hr = hr
self.min = min
self.sec = sec
class Clock(TimeType):
month_days =[31,28,31,30,31,30,31,31,30,31,30,31]
def __init__(self):
super().__init__(0,0,0)
self.month =1
self.day =1
self.year =1980
@classmethod
def leap_year(cls, year):
if year %400==0:
return True
elif year %100==0:
return False
elif year %4==0:
return True
else:
return False
def set_clock(self, hrs, mins, secs, mon, dy, yr):
if mon <1 or mon >12:
return False
if dy <1 or dy > self.month_days[mon -1]:
return False
if mon ==2 and dy ==29 and not self.leap_year(yr):
return False
self.hr = hrs
self.min = mins
self.sec = secs
self.month = mon
self.day = dy
self.year = yr
return True
def increase_day(self):
if self.day < self.month_days[self.month -1]:
self.day +=1
else:
self.day =1
if self.month <12:
self.month +=1
else:
self.month =1
self.year +=1
if self.leap_year(self.year):
self.month_days[1]=29
else:
self.month_days[1]=28
def decrease_day(self):
if self.day >1:
self.day -=1
else:
if self.month >1:
self.month -=1
self.day = self.month_days[self.month -1]
else:
self.year -=1
self.month =12
self.day =31
def increase_second(self):
self.sec +=1
if self.sec ==60:
self.sec =0
self.min +=1
if self.min ==60:
self.min =0
self.hr +=1
if self.hr ==24:
self.hr =0
self.increase_day()
def decrease_second(self):
self.sec -=1
if self.sec ==-1:
self.sec =59
self.min -=1
if self.min ==-1:
self.min =59
self.hr -=1
if self.hr ==-1:
self.hr =23
self.decrease_day()
def __str__(self):
am_pm ="AM" if self.hr <12 else "PM"
hour = self.hr if self.hr <=12 else self.hr -12
if hour ==0:
hour =12
return f"{self.month}/{self.day}/{self.year}{hour:02d}:{self.min:02d}:{self.sec:02d}{am_pm}"
# Test client
clock = Clock()
print(clock) # Should print "1/1/198012:00:00 AM"
clock.set_clock(23,59,59,2,28,2020)
print(clock) # Should print "2/28/202011:59:59 PM"
clock.increase_second()
print(clock) # Should print "2/29/202012:00:00 AM"(leap year)
clock.decrease_second()
print(clock) # Should print "2/28/202011:59:59 PM"(leap year)
my code is not printing leap year, how can I fix that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!