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 storage unit in computer and five examples of storage units.<br>​
Juliette [100K]

Answer:

the storage unit of a computer is known as the term which is used to indicate storage capacity.

Explanation:

Five units of storage units are:-

1) byte

2) kilobyte

3) megabyte

4) gigabyte

5) terabyte

7 0
2 years ago
Read 2 more answers
Write the definition of a function named printpoweroftwostars that receives a non-negative integer n and prints a line consistin
Aleksandr-060686 [28]
To accomplish this without using a loop,
we can use math on a string.

Example:
print("apple" * 8)

Output:
appleappleappleappleappleappleappleapple

In this example,
the multiplication by 8 actually creates 8 copies of the string.

So that's the type of logic we want to apply to our problem.

<span>def powersOfTwo(number):
if number >= 0:
return print("*" * 2**number)
else:
<span>return

Hmm I can't make indentations in this box,
so it's doesn't format correctly.
Hopefully you get the idea though.

We're taking the string containing an asterisk and copying it 2^(number) times.

Beyond that you will need to call the function below.
Test it with some different values.

powersOfTwo(4) should print 2^4 asterisks: ****************</span></span>
4 0
3 years ago
Which term describes a protocol to manage a network, able to configure a network, monitor activity, and control devices?
natali 33 [55]
The answer is c post office protocol version 3 (POP 3)
7 0
2 years ago
Quand on veut, on .<br> veut<br> doit<br> arrive<br> peut
Talja [164]

<em>Bonjour,</em>

<em />

<em>Quand on veut, </em>on peut.

Verbe "pouvoir" au présent :

<em>je peux</em>

<em>tu peux</em>

<em>il, elle, </em>on  peut

<em>nous pouvons</em>

<em>vous pouvez</em>

<em>ils, elles peuvent</em>

7 0
2 years ago
Compare and contrast the android and windows operating systems
pantera1 [17]
The main difference between Windows and OS X is the computer you can use it with. OS X is exclusively for Apple computers, commonly known as Macs, while Windows is basically for any personal computer from any company.
3 0
2 years ago
Other questions:
  • Give reasons why mind-mapping software is important to project development.
    14·1 answer
  • What is imagined risk
    12·1 answer
  • How many hosts are in each subnet?
    15·1 answer
  • Briefly explain what are JavaScript librairies​
    12·1 answer
  • Which are examples of non-linear presentations? Choose all that apply.
    11·1 answer
  • Public relations strives to foster goodwill between a client and a audience ​
    8·1 answer
  • In this lab, you complete a C++ program that uses an array to store data for the village of Marengo.
    8·1 answer
  • Which diagram is NOT a good model of 3÷14?
    12·2 answers
  • Brianna is feeling overwhelmed by the amount of digital
    13·1 answer
  • A _____ system allows a customer to request a fax using email, via the company website, or by telephone.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!