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
What is the difference between a switch's physical interface and the vlan interface?
Andreyy89
<span>Switch's physical interface is something as the name itself suggests itself that it is a physical port to which you can plug in a cable or a wire based on its function and usage where as VLAN interface is no physical port but are created virtually when needed.</span>
4 0
3 years ago
Read 2 more answers
How can you troubleshoot Internet access problems?
joja [24]

Answer:

Check the network icon (or wireless connection settings) to see if you have Internet access. ...

Check for changes to proxy settings.

Check the network cables if your computer is wired to the router.

Reset your router.

Check your firewall or security software.

Hopefully this helps.

8 0
3 years ago
What is the lucky 3 digit today
victus00 [196]
That is an interactive question.
4 0
3 years ago
What is SEO?<br> Training Live Online Instructor-Led Learning, https://www.peoplentech.com.bd/<br> ,
evablogger [386]

Answer:Search engine optimization (SEO) is the process of optimizing your online content so that a search engine likes to show it as a top result for searches of a certain keyword. ... When it comes to SEO, there's you, the search engine, and the searcher.

Explanation:

4 0
2 years ago
Which of the following is NOT a popular computer programming
cestrela7 [59]
Answer is Xero. All the other Languages are Popular and Widely Used.
Thank You!
6 0
2 years ago
Other questions:
  • Explain how buyers and sellers factor into setting the stock price for a company’s shares.
    13·1 answer
  • What software refers to the on authorized and illegal duplication or sale of software
    10·1 answer
  • Which protocol do e-mail programs use to identify the file types of attached files?
    7·1 answer
  • In the SQL environment, a _____________ is a logical group of database objects – such as tables and indexes – that are related t
    11·1 answer
  • How are IP addresses usually written?
    7·1 answer
  • Technology trends in education play a key role in a student’s
    15·1 answer
  • How do you determine which type of operating system that best supports your computer or mobile device?
    5·1 answer
  • One key feature of malware is that it:
    13·1 answer
  • What are your two biggest strengths as a student? How will these strengths help you become a self-directed learner?
    13·2 answers
  • Which is a linear presentation?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!