answer.
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
Snezhnost
3 months 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:
Harlamova29_29 [1K]3 months 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 is designed to ensure that the user inputs a valid month and day. The try and except blocks paired with IF statements work together to achieve accurate results. The while loop continues until a legitimate input is received.

The first try block checks if the month provided exists by comparing it against a predefined list. If it fails, an error is raised, triggering the except block that informs the user of the invalid entry.

When the first TRY block succeeds, it moves to the next stage, which takes a number input, confirming that it is correct for each month. Any invalid input leads to an error, stimulating the try block to print the issue.

If all inputs are valid, the program exits the loop and transitions to the subsequent section.

#SECTION 2

This part uses the given data to determine the season, leveraging IF statements to produce the result, which it then prints.

I have attached a sample for you to see how the code operates using both incorrect and correct input values.

Amiraneli [1K]3 months 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 ('October', 'November', 'December'):

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 in ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')) and ((day < 1) or (day > 31)):

   season = 'Invalid'

print(season)

Explanation:

You might be interested in
The president of the company wants a list of all orders ever taken. He wants to see the customer name, the last name of the empl
zubka84 [1067]

Response:

refer to the explanation

Clarification:

Examine the SQL statement shown below:

SELECT c.CustomerName, e.LastName, s.ShipperName, p.ProductName, o.Quantity, od.OrderDate

FROM

Customers c, Employees e, Shippers s, Orders o, OrderDetails od, Products p

WHERE c.customerID = o.customerID AND

e.employeeID = o.employeeID AND

o.orderID = od.orderID AND

od.shipperID = s.shipperID AND

od.productID = p.productID;

6 0
2 months ago
You work in the educational software industry. Your boss asks you to give a brief lecture to other employees about the digital d
Harlamova29_29 [1022]
Joe mama is the most extraordinary person on the planet.
5 0
2 months ago
Read 2 more answers
7. Which of these statements is true? Agile is a programming language MySQL is a database HTML stands for "Hypertext Markup Link
Harlamova29_29 [1022]

Answer:

None of the statements are accurate, although one option appears to lack certain words.

The precise definition is that MySQL functions as a database management system.

Explanation:

Agile is a software development methodology, not a programming language.

HTML denotes "Hypertext Markup Language"

Java and JavaScript are distinct programming languages.

In fact, MySQL serves as a database management system, specifically for managing relational databases, utilizing SQL (Structured Query Language).

5 0
3 months ago
Write an if-else statement to describe an integer. Print "Positive even number" if isEven and is Positive are both true. Print "
Harlamova29_29 [1022]

Answer:

Below is the explanation for the C code.

Explanation:

#include <stdio.h>

#include <stdbool.h>

int main(void) {

int userNum;

bool isPositive;

bool isEven;

scanf("%d", &userNum);

isPositive = (userNum > 0);

isEven = ((userNum % 2) == 0);

if(isPositive && isEven){

  printf("Positive even number");

}

else if(isPositive &&!isEven){

  printf("Positive number");

}

else{

  printf("Not a positive number");

}

printf("\n");

return 0;

}

6 0
2 months ago
Other questions:
  • Why were the practitioners of alternative software development methods not satisfied with the traditional waterfall method?
    9·1 answer
  • 3.14 LAB: Input and formatted output: Caffeine levels A half-life is the amount of time it takes for a substance or entity to fa
    9·1 answer
  • Write a sequence of statements that create a file named "greeting" and write a single line consisting of "Hello, World!" to that
    5·1 answer
  • Form the recurrence relations (RRs) for the number of vertices and the number of edges of a hypercube of n dimensions, Hn. Solve
    13·1 answer
  • Assign max_sum with the greater of num_a and num_b, PLUS the greater of num_y and num_z. Use just one statement. Hint: Call find
    5·1 answer
  • If a cell reference is c6, this cell is in the sixth column and the third row. true or false
    11·2 answers
  • Danielle, a help desk technician, receives a call from a client. In a panic, he explains that he was using the Internet to resea
    9·1 answer
  • What problem does the DNS solve? How does the DNS help the world wide web scale so that billions of users can access billions of
    11·1 answer
  • The function below takes two numeric parameters. The first parameter specifies the number of hours a person worked and the secon
    13·1 answer
  • JAVA Write a program that first asks the user to type a letter grade and then translates the letter grade into a number grade. L
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!