1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
velikii [3]
3 years ago
13

Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an in

t to represent the day. Ex: If the input is April 11, the output is: spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is invalid, the output is: invalid The dates for each season are: spring: March 20 - June 20 summer: June 21 - September 21 autumn: September 22 - December 20 winter: December 21 - March 19

Computers and Technology
2 answers:
victus00 [196]3 years ago
4 0

Answer:

#SECTION 1

while True:

   month = input("Input the month (e.g. January, February etc.): ")

   try:

       

       if month in ('January', 'February', 'March','April', 'May', 'June','July', 'August', 'September', 'October', 'November', 'December',):

           day = int(input("Input the day: "))

           try:

               if day > 31:

                   raise

               elif day == 31 and month in ('September', 'April', 'June', 'November'):

                   raise

               elif day > 29 and month == 'February':

                   raise

               else:

                   break

                   

           except:

               print('Invalid!!!')

               print('Day not correct')

           

       else:

           raise

   except:

       print('Invalid!!!')

       print('Enter correct Month')

 

     

#SECTION 2

if month in ('January', 'February', 'March'):

season = 'winter'

elif month in ('April', 'May', 'June'):

season = 'spring'

elif month in ('July', 'August', 'September'):

season = 'summer'

else:

season = 'autumn'

if (month == 'March') and (day > 19):

season = 'spring'

elif (month == 'June') and (day > 20):

season = 'summer'

elif (month == 'September') and (day > 21):

season = 'autumn'

elif (month == 'December') and (day > 20):

season = 'winter'

print("Season is",season)

Explanation:

#SECTION 1

This section ensures that a correct input is inserted. The try and except blocks in combination with IF statements are used to archive the result. The while loop will continue to run until a valid input is inserted.

In the first try block, It checks to see if the month inputted is a month that exists by comparing it  with a list of months, if it does not exist it raises an error and executes the except block and prints invalid and states the error that occurred.

If the first  TRY block executes successful, the program moves to the next, it takes an input for the number and ensures that us a valid number for each month. If the number is invalid, it raises an error and executes the try block which prints invalid and states the problem.

If al inputs are valid the program breaks out of the loop and proceeds to the next section.

#SECTION 2

In this section the data provided is used to calculate the season, by making use of IF statements and finally the season is printed.

I have attached a sample for you to see how the code runs by inputting some inaccurate values and accurate ones.

Diano4ka-milaya [45]3 years ago
3 0

Answer:

month = input()

day = int(input())

 

if month in ('January', 'February', 'March'):

season = 'Winter'

elif month in ('April', 'May', 'June'):

season = 'Spring'

elif month in ('July', 'August', 'September'):

season = 'Summer'

elif month in ('November'):

season = 'Autumn'

else:

   season='Invalid'

   

if (month == 'March') and (day > 19):

season = 'Spring'

elif (month == 'June') and (day > 20):

season = 'Summer'

elif (month == 'September') and (day > 21):

season = 'Autumn'

 

elif (month == 'December') and (day > 20):

season = 'Winter'

 

if (month =='January', 'February', 'March','April', 'May', 'June','July', 'August', 'September', 'October', 'November', 'December') and ((0>day)or(day>30)):

   season='Invalid'

#make sure to add the last line because they will ask about the day "39"  which is invalid

print(season)

Explanation:

You might be interested in
Yolanda is making a banner for a school pep rally. She cuts fabric in the shape of a parallelogram. The angle at the bottom left
Irina18 [472]

The answer is 100°

A parallelogram is any four sided shape with two pairs of opposite parallel and equal length sides. It is safe to say that a square is a parallelogram and not the other way round.

To explain how we got to 100 degrees, I have attached an image. Based on the image attached, the opposite angles are equal. The adjacent angles are supplementary. With this in mind, the supplement of 80° will be 100°


5 0
3 years ago
Read 2 more answers
A data visualization tool that updates in real time and gives multiple outputs is called
strojnjashka [21]

Answer:

A data dashboard

Explanation:

3 0
2 years ago
What is the name of the most common connector type used for providing power to various hardware components inside computer case?
user100 [1]
The answer is the molex.
4 0
3 years ago
Perfective maintenance usually is cost effective ____ the system
Svetlanka [38]

Answer:

During the middle of

Explanation:

Perfective maintenance usually is cost effective during the middle of the system.

6 0
3 years ago
Read 2 more answers
According to the lecture, in communication, men tend to value ____________.
Andru [333]

Answer:

respect?

Explanation:

8 0
3 years ago
Other questions:
  • for which is a chart legend used? a.all of the time b.whenever you are comparing data that is the same c.whenever you are compar
    9·2 answers
  • Fill in the blank
    11·1 answer
  • Which represents the hierarchical structure of a Google Analytics account from top to bottom?
    5·1 answer
  • When you are given a set of tables and asked to create a database to store their data, the first step is to ________?
    8·1 answer
  • If we compare the push function of the stack with the insertFirst function for general lists, we see that the algorithms to impl
    9·1 answer
  • UC is trying to switch from legacy CRM to salesforce and wants to keep legacy CRM and salesforce in place till all the functiona
    9·1 answer
  • Compound conditions require a computer to sense whether multiple conditions are true or false.
    9·1 answer
  • There are types of templates​
    5·1 answer
  • Which type of mic is durable, versatile and does not rely on power?
    14·2 answers
  • When using the text command, what needs to be around the word or words you<br> want to appear?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!