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
1 month 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 [932]1 month 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 [921]1 month 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 Pentium 4 Prescott processor, released in 2004, had a clock rate of 3.6 GHz and voltage of 1.25 V. Assume that, on average,
Natasha_Volkova [897]

Answer:

1. The capacitive load for the Pentium 4 Prescott processor is 32 nF. For the Core i5 Ivy processor, it is 29.05 nF.

2. The static power makes up 10% of the total power dissipated for the Pentium 4 Prescott processor. The static to dynamic power ratio is 0.11.

For the Core i5 Ivy Bridge processor, the static power percentage is 42.86%. The ratio of static to dynamic power stands at 0.75.

3. The voltage reduction for the Pentium 4 Prescott processor equals a decrease of 5.9 %.

The Core i5 Ivy Bridge processor sees a 9.8 % reduction in voltage.

Explanation:

1. Recognizing dynamic power, P as approximately 1/2 CV²f, where C is the transistor's capacitive load, v denotes voltage, and f is frequency.

Thus, C is found using the formula C ≈ 2P/V²f.

For the Pentium 4 Prescott processor, with V₁ = 1.25 V, f₁ = 3.6 GHz, and P₁ = 90 W, we denote its capacitive load as C₁. Thus, we find C₁ ≈ 2P/V²f = 2 × 90 W/(1.25 V)² × 3.6 × 10⁹ Hz = 3.2 × 10⁻⁸ F = 32 × 10⁻⁹ F = 32 nF.

For the Core i5 Ivy Bridge processor, with V = 0.9 V, f = 3.4 GHz, and P = 40 W, we define C₂ as its load. Therefore, C₂ ≈ 2P/V²f = 2 × 40 W/(0.9 V)² × 3.4 × 10⁹ Hz = 2.905 × 10⁻⁸ F = 29.05 × 10⁻⁹ F = 29.05 nF.

2. The summation of total power is derived from static plus dynamic power.

For Pentium 4 Prescott, static power adds to 10 W and dynamic power is 90 W. Hence, the overall power, P = 10 W + 90 W = 100 W.

The fraction of this total attributed to static power is calculated as static power over total power multiplied by 100, thus static power/total power × 100 = 10/100 × 100 = 10%.

The ratio of static to dynamic power equals static power over dynamic power = 10/90 = 0.11.

For the Core i5 Ivy Bridge, static power figures at 30 W, and dynamic power at 40 W, meaning the total power becomes P = 30 W + 40 W = 70 W.

The portion of the total power that is static is computed as static power/total power × 100 = 30/70 × 100 = 42.86%.

That ratio of static to dynamic stands at static power/dynamic power = 30/40 = 0.75.

3. The total power comprises static and dynamic contributions and resulting leakage current arises from static power. We understand that P = IV, hence leakage current, I = P/V.

With an intended total power reduction of 10%, we have P₂ = (1 - 0.1)P₁ = 0.9P₁, where P₁ is the initial dissipated power before the 10% decrement and P₂ represents the new dissipated power.

Hence, new total dissipated power P₂ = new static power I₂V₂ + new dynamic power 1/2C₂V₂²f₂ = 0.9P₁.

For the Pentium 4 Prescott with P₂ = I₂V₂ + 1/2C₂V₂²f₂ = 0.9P₁, given I₂ as leakage current which equals static power/voltage = 10 W/1.25 V = 8 A (since leakage remains constant), we determine

8 A × V₂ + 1/2 × 32 × 10⁻⁹ F × V₂² × 3.6 × 10⁹ Hz = 0.9 × 100.

This simplifies to 8V₂ + 57.6V₂² = 90, leading to the quadratic equation.

57.6V₂² + 8V₂ - 90 = 0, from which applying the quadratic formula yields

V₂ = \frac{-8 +/- \sqrt{8^{2} -4X57.6 X -90} }{2X57.6} = \frac{-8 +/- \sqrt{64 + 20736} }{115.2} = \frac{-8 +/- \sqrt{20800} }{115.2}\\=\frac{-8 +/- 144.222}{115.2}\\.

Choosing the positive result, V₂ arrives at 1.18 V. The calculated reduction percentage is given by (new voltage - old voltage)/new voltage × 100% = (1.18 - 1.25)/1.18 × 100% = -0.07/1.18 × 100% = -5.9% with a 5.9% drop from 1.25V.

For the Core i5 Ivy Bridge processor, it follows that P₂ = I₂V₂ + 1/2C₂V₂²f₂ = 0.9P₁. With I₂ as leakage current equaling static power/voltage = 30 W/0.9 V = 33.33 A (again, leakage remains constant), we next evaluate

33.33 A × V₂ + 1/2 × 29.05 × 10⁻⁹ F × V₂² × 3.4 × 10⁹ Hz = 0.9 × 70.

This resolves to 33.33V₂ + 49.385V₂² = 63. Thus, it simplifies to the quadratic equation

49.385V₂² + 33.33V₂ - 63 = 0, whereby employing the quadratic formula lets us find

V₂ = \frac{-49.385 +/- \sqrt{49.385^{2} -4X33.33 X -63} }{2X33.33} = \frac{-49.385 +/- \sqrt{2438.8782 + 8399.916} }{66.66} = \frac{-49.385 +/- \sqrt{10838.794} }{66.66}\\=\frac{-49.385 +/- 104.110}{66.66}\\.

Choosing the positive answer provides a new voltage of 0.82 V. The percentage reduction computes as (new voltage - old voltage)/new voltage × 100% = (0.82 - 0.9)/0.82 × 100% = -0.08/0.82 × 100% = -9.8% with a 9.8% decrease from 0.9V.

6 0
1 month ago
Tanya wants to include a video with all its controls on her web page. The dimensions of the video are as follows:
Natasha_Volkova [897]
I believe the correct answer is formats
4 0
12 days ago
Read 2 more answers
Find true or false. A hacker is hacking software with access in sensitive information from your computer​
Harlamova29_29 [932]
IT'S CORRECT!! I LOOKED IT UP
7 0
20 days ago
A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a fi
oksian1 [797]

Answer:

Below is the Python code with suitable comments.

Explanation:

#Input file name acquisition

filename=input('Enter the input file name: ')

#Opening the input file

inputFile = open(filename,"r+")

#Dictionary definition.

list={}

#Read and split file content using a loop

for word in inputFile.read().split():

#Check if the word exists in the file.

if word not in list:

list[word] = 1

#Increment count by 1

else:

list[word] += 1

#Closing the file.

inputFile.close();

#Output a blank line

print();

#Sorting words according to their ASCII values.

for i in sorted(list):

#Display unique words along with their

#frequencies in alphabetical order.

print("{0} {1} ".format(i, list[i]));

3 0
1 month ago
Write an expression to print each price in stock_prices. Sample output with inputs: 34.62 76.30 85.05
8_murik_8 [892]

Answer:

Below is the Python code:

stock_prices = input().split() #this takes input and separates it into a list

for price in stock_prices: #this loops through each stock price

   print("$",price) #this outputs each stock price prefixed by a dollar sign

Explanation:

The logic behind the program is clearly outlined in the attached comments. To illustrate the program's workings, let's consider an example:

Imagine the user inputs the stock_prices values of

34.62 76.30 85.05

The input() method captures user input, while the split() method divides the input string, providing a list of strings as:

['34.62', '76.30', '85.05']

Following that, the loop statement for price in stock_prices: iterates through each item in the list, and print("$",price) displays each value from the list on the output screen with a dollar sign, as follows:

$ 34.62                                                                                                            

$ 76.30                                                                                                            

$ 85.05    

4 0
1 month ago
Other questions:
  • In the middle of the iteration, how should a team handle requirement changes from the customer? (1 correct answer)
    7·2 answers
  • Write a function solution that returns an arbitrary integer which is greater than n.
    13·1 answer
  • When a CPU executes instructions as it converts input into output, it does so with
    12·1 answer
  • This question involves a simulation of a two-player game. In the game, two simulated players each start out with an equal number
    7·1 answer
  • Initialize the list short_names with strings 'Gus', 'Bob', and 'Zoe'. Sample output for the givenprogram:Gus Bob Zoeshort_names
    13·1 answer
  • What is the other name designated to a game master of multiplayer online games (MMOs)?
    11·2 answers
  • Factoring of integers. Write a python program that asks the user for an integer and then prints out all its factors. For example
    13·1 answer
  • Assign to avg_owls the average owls per zoo. Print avg_owls as an integer. Sample output for inputs: 1 2 4 3
    7·1 answer
  • This question refers to a standard deck of playing cards. If you are unfamiliar with playing cards, there is an explanation in P
    10·2 answers
  • Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined in a namespace royaltyRates. PLEASE DONT F
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!