Question
Below is the class definition for a Date class. It represents data using integers for the month and day. For example, February 5 has month
Below is the class definition for a Date class. It represents data using integers for the month and day. For example, February 5 has month number 2 and day equal to 5.
class Date:
def __init__ (self, month, day, year):
self.month = month
self.day = day
def advance(self):
self.day += 1
monthLengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if self.day > monthLengths[self.day]:
self.day = 1
self.month += 1
if self.month > 12:
self.month = 1
Note: this data class ignores leap year.
A. The advance method has a single error that does not relate to leap year. Find the error and change the code to remove the error.
B. Implement the str method for the class. It should give a string representation of the date using the month name and date.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started