In: Computer Science
The assignment is to write a class called data. A Date object is intented to represent a particuar date's month, day and year. It should be represented as an int.
-- write a method called earlier_date. The method should return True or False, depending on whether or not one date is earlier than another. Keep in mind that a method is called using the "dot" syntax. Therefore, assuming that d1 and d2 are Date objects, a valid method called to earlier_date would be
>>> d1.earlier_date(d2)
and the method should return True if d1 is earlier than d2, or False otherwise. For example:
>>> today = Date(1,23,2017)
>>> y2k.earlier_date(today)
True
>>> today.earlier_date(mlk_day)
False
>>> feb_29.earlier_date(march_1)
True
python 2.7.13
class Date:
def __init__(self,month,day,year):
self.month = month
self.day = day
self.year = year
def earlier_date(self,x):
if self.year==x.year and self.month==x.month and self.day==x.day
:
return True
else:
return False
d1=Date(1,23,2017)
d2=Date(2,23,2017)
d1.earlier_date(d2)
y2k=Date(1,24,2017)
today = Date(1,24,2017)
y2k.earlier_date(today)
Code Image:
Output Image: