Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Discuss the Hawthorne experiments in detail

Answered: 1 week ago

Question

Explain the characteristics of a good system of control

Answered: 1 week ago

Question

State the importance of control

Answered: 1 week ago

Question

What are the functions of top management?

Answered: 1 week ago

Question

6. Discuss the steps involved in conducting a task analysis.

Answered: 1 week ago

Question

8. Explain competency models and the process used to develop them.

Answered: 1 week ago