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 type of camera is a cell phone camera
Sergeeva-Olga [200]

Answer:

A camera phone is a mobile phone which is able to capture photographs and often record video using one or more built-in digital cameras. It can also send the resulting image over the telephone function. The first commercial camera phone was the Kyocera Visual Phone VP-210, released in Japan in May 1999.

Explanation:

Hope this kinda helps you :)

3 0
3 years ago
Read 2 more answers
The output for the following code will be: Pasta (1 mark)
Anastasy [175]

Answer:

The output is "Pasta"

Explanation:

Given

The attached code segment

Required

The output

The first line of the program implies that:

MyFavFood="Pasta"

This means that, the value of the variable MyFavFood is string "Pasta"

Next,

print (MyFavFood)

This prints the value of the variable MyFavFood which is "Pasta"

<em>Hence, the output is "Pasta"</em>

7 0
2 years ago
How many 1000-Watt lights can be plugged into a standard 120-Volt, 15-Amp outlet? (Hint: W/V=A) *
Licemer1 [7]

Answer:

There are up to 12 lights and or plugs on that circuit. A 1000w HPS or Metal Halide light takes 9 amps at 120 volts so you can only run one on a wall outlet circuit. A standard dryer outlet is 220 volts and 30 amps so you can power up to six 1000 watt lights on that circuit.

5 0
3 years ago
Why team goals should be broken into shon-term, medium-term, and long-term goals
lora16 [44]

Answer:

Explanation: Goals should be broken down according to time because it allows the team to decide what their overall purpose is, and to define the actions that will allow them to achieve their overall purpose.

7 0
3 years ago
Read 2 more answers
Interviews should never feel like an_________Instead, they should feel like a________
Rainbow [258]

Answer:

blank 1: interrogation

blank 2: getting to know

Explanation:

4 0
3 years ago
Other questions:
  • . Alex discovered a bunch of SATA drives in a box at the office and needs to check the contents. What can he do so that Windows
    13·1 answer
  • What are the 6 external parts of a computer
    14·1 answer
  • What is the differnces between dark and middle ages of computer?​
    9·1 answer
  • Suppose you were assigned to develop a logical model of the registration system at a school or college. would you be better off
    9·1 answer
  • Which object waits for and responds toan event from a GUI component?
    9·1 answer
  • Which search engine do you prefer? Why
    15·2 answers
  • Write a method printshampoolnstructions0, with int parameter numCycles, and void return type. If numCycles is less than 1, print
    8·1 answer
  • Consider a system consisting of processes P1 , P2 , ..., Pn , each of which has a unique priority number. Write a monitor that a
    14·1 answer
  • Macro photographs are what type of photographs? A. Close-up B. Telephoto C. Abstract D. All of the above
    14·1 answer
  • PLS HELP WITH MY PYTHON HW ILL GIVE YOU BRAINLIEST
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!