Hello, I created a class in Python and am struggling to figure out how to complete the last part. How can you verify that a date is before in a pythonic way? I am struggling with the operands and what to check first. Thank you!
class Date(object):
"Represents a Calendar date"
def __init__(self, day=0, month=0, year=0):
"Initialize"
self.day = day
self.month = month
self.year = year
def __str__(self):
"Return a printable string representing the date: m/d/y"
return f'{self.month}/{self.day}/{self.year}'
def before(self, other):
"Is this date before that?"
class Date(object): "Represents a Calendar date" def __init__(self, day=0, month=0, year=0): "Initialize" self.day = day self.month = month self.year = year def __str__(self): "Return a printable string representing the date: m/d/y" return f'{self.month}/{self.day}/{self.year}' def before(self, other): "Is this date before that?" if self.year < other.year: return True if self.year == other.year and self.month < other.month: return True if self.year == other.year and self.month == other.month and self.day < other.day: return True return False
Get Answers For Free
Most questions answered within 1 hours.