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

PYTHON 1 from goody import irange, type asstr 2 36 class Date: 4 month-dict {1:3

ID: 3602796 • Letter: P

Question

PYTHON

1 from goody import irange, type asstr 2 36 class Date: 4 month-dict {1:31, 2:28, 3:31, 4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31) @staticmethod 6 7e def is_leap_ year(year): 8 9 10 11 def days_in(year,month): 12 13 14 15 16 17 18 if name ==' main ': 19 20 return (year%4-0 and year%100 != 0) or year%400 == 0 @staticmethod return Date.month dict month(1 if month2 and Date.is leap year(year) else 0) # Put in simple tests for Date before allowing driver to run print() import driver 23 24 driver.default file name = 'bsc1.txt' 26 # 27 # 28 driver . default show traceback = True driver.default.-show exception = True driver . default-show exception-message = True driver.driver()

Explanation / Answer

(4) - # FUNCTION which returns number of days have elapsed from january 1st inthe year 0 def len(year,month,days): sum1 = 0 for i in range(year): for j in range(1,13): sum1 += Date.days_in(i,j) # add all days of years before current year for i in range(1,month): sum1 += Date.days_in(year,i) # add all days of months before current months in current year return (sum1+days-1) # add days of current month before the given day in current month (5) - # the overloading function for (==) operator in Date class def __eq__(first,other): if (type(first) of Date and type(other) is Date): # first check type of both the operand return (Date.len(first)== Date.len(other)) # compare the number of days of both given dates else: return False