We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importosimportsys## Complete the 'libraryFine' function below.## The function is expected to return an INTEGER.# The function accepts following parameters:# 1. INTEGER d1# 2. INTEGER m1# 3. INTEGER y1# 4. INTEGER d2# 5. INTEGER m2# 6. INTEGER y2#classDate:def__init__(self,day,month,year):self.day=dayself.month=monthself.year=yeardef__lt__(self,other):ifself.year!=other.year:returnself.year<other.yearifself.month!=other.month:returnself.month<other.monthreturnself.day<other.daydef__eq__(self,other):returnself.year==other.yearandself.month==other.monthandself.day==other.daydef__str__(self):returnf"{self.day} {self.month} {self.year}"classLibraryFineCalculator:def__init__(self):self.fine=0defcalculate_fine(self,actual_date,expected_date):ifactual_date<expected_dateoractual_date==expected_date:self.fine=0else:ifactual_date.year>expected_date.year:self.fine=10000elifactual_date.year==expected_date.year:ifactual_date.month>expected_date.month:self.fine=500*(actual_date.month-expected_date.month)elifactual_date.month==expected_date.month:ifactual_date.day>expected_date.day:self.fine=15*(actual_date.day-expected_date.day)returnself.finedefparse_date(day,month,year):returnDate(day,month,year)deflibraryFine(d1,m1,y1,d2,m2,y2):actual_date=parse_date(d1,m1,y1)expected_date=parse_date(d2,m2,y2)calculator=LibraryFineCalculator()returncalculator.calculate_fine(actual_date,expected_date)if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')first_multiple_input=input().rstrip().split()d1=int(first_multiple_input[0])m1=int(first_multiple_input[1])y1=int(first_multiple_input[2])second_multiple_input=input().rstrip().split()d2=int(second_multiple_input[0])m2=int(second_multiple_input[1])y2=int(second_multiple_input[2])result=libraryFine(d1,m1,y1,d2,m2,y2)fptr.write(str(result)+'\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Library Fine
You are viewing a single comment's thread. Return to all comments →
My solution using Python.