Question
Question: Write a function in Python that is passed a year, a month and a day, and then returns the season, and the number of
Question: Write a function in Python that is passed a year, a month and a day, and then returns the season, and the number of days past since the beginning of this season as a two-element list. For the purposes of this lab, you may assume that spring, summer, autumn, and winter begin on the 21st day of March, June, September, and December, respectively. Make sure to pay attention to leap years (google how to check for leap years).
If program is passed an invalid entry for the month or the day, the program should return ['invalid month', -1] or ['invalid day', -1], respectively. If passed both an invalid month and an invalid day, the program should return ['invalid month', -1].
Sample Inputs and Outputs:
Inputs: seasons(year, month, day)
seasons(1998, 3, 22) seasons(1998, 0, 40) seasons(1998, 1, 32) seasons(1998, 2, 29) seasons(2000, 2, 29)
Output
['spring', 1] ['invalid month', -1] ['invalid day', -1] ['invalid day', -1] ['winter', 70]
Hints:
-
You may find creating a list of days for each month helpful for your calculation.
-
Be careful with winter, as it extends over the end of the year.
-
You may want to calculate the number of days between Jan 1 and the input date.
The initial code given:
def seasons(year, month, day): """ (int, int, int) -> [str, int] A function that is passed a month and day, determines the season, and then calculates the number of days since the current season begins and returns the season and days as a two element list.
Students may assume that the seasons begin on the 21st day of March, June, September and December. Student SHOULD consider leap year.
Please refer to the handout for test cases and error conditions. """
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