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
gavmur [86]
3 years ago
11

Write a Python program (rainfall.py) to collect data and calculate the average rainfall over a period of years. The program shou

ld first ask for the number of years. Then for each year, the program should ask twelve times, once for each month, for inches of rainfall for that month. At the end, , the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period.
Your program should contain two functions:

(1) rainfall(year): This function takes in a year (integer) as a parameter, and returns two values (totalMonths and totalRainfall). In this function, you need to use nested loop. The outer loop will iterate once for each year. The inner loop will iterate twelve times, once for each month. Each iteration of the inner loop will ask the user for inches (float) of rainfall for that month. After all iterations, the function should return the number of months (totalMonths) and the total inches of rainfall (totalRainfall). (Submit for 4 points)

(2) __main__: In the main, you do the following: (Submit for 6 points)

a. Prompt the user to input the number of years. Reprompt the user if the number of years is 0 or less. Hint: use a while loop.
b. Call rainfall(year) and pass to it the value entered above.
c. Calculate the average based on the returned values from rainfall function.
d. Display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period.
Computers and Technology
1 answer:
RSB [31]3 years ago
5 0

Answer:

def rainfall(year):

   totalMonths = totalRainfall = 0

   for y in range(year):

       for month in range(12):

           rainfall = float(input(f"Enter inches of rainfall for month #{month+1}: "))

           totalRainfall += rainfall

   totalMonths = year * 12

   return totalMonths, totalRainfall

def __main__():

   while True:

       year = int(input("Enter the number of years: "))

       if year > 0:

           break

   numberOfMonths, totalRainfall = rainfall(year)

   averageRainFall = totalRainfall / numberOfMonths

   print(f"\nTotal number of months: {numberOfMonths}")

   print(f"The total inches of rainfall: {totalRainfall}")

   print(f"The average rainfall per month for the entire period: {averageRainFall}")

if __name__ == '__main__':

   __main__()

Explanation:

Create a function named rainfall that takes year as a parameter

Inside the function:

Create a nested for loop. The outer loop iterates for each year (The range is from 0 to year-1) and the inner loop iterates for each month of that year (The range is from 0 to 11). Inside the inner loop, ask the user to enter the rainfall for that month. Add the rainfall to the totalRainfall (cumulative sum)

When the loops are done, calculate the totalMonths, multiply year by 12

Return the totalMonths and totalRainfall

Inside the main:

Create a while loop that asks user to enter the number of years while it is greater than 0

Call the rainfall function, passing the year as parameter. Set the numberOfMonths and totalRainfall using the rainfall function

Calculate the averageRainFall, divide totalRainfall by numberOfMonths

Print the results

You might be interested in
Bugs bunny personality traits
Dafna1 [17]

Answer:

As a character, Bugs Bunny is king, and he's as close to an animated culture hero as we're going to get. Think about it. He's the person you want to be — the smartest one in the room who's still effortlessly cool. He's quick-witted, funny, and even a little cruel, but only to his tormenters.

Explanation:I hope this helps!!!Plz leave a heart and a rating!!

3 0
4 years ago
What command issued from the command prompt will show the route that a packet travels from the issuing computer to another compu
svetoff [14.1K]

Answer:

B)tracert

Explanation:

Tracery Command can be regarded as

network diagnostic tool, it is used in tracking process of pathway of packet ranging from source to destination on IP network. It as well allows to know real time of each hops that are been taken by a packet as it enroutes to it's destination. The traceroute can be run by following these steps:

✓Open the run window

✓Open Command prompt, this can be done by enter "cmd" then enter.

✓ input" tracert" then destination ( Ip address or web address)

It should be noted that Tracery command issued from the command prompt will show the route that a packet travels from the issuing computer to another computer.

6 0
3 years ago
To use the shortcut for inserting a row,_____
lesya692 [45]
I think it is double click
8 0
3 years ago
The eight great ideas in computer architecture are similar ideas from other fields. Match the eight ideas from computer architec
andrew11 [14]

Answer:

following are the answer to this question:

In option a, "Performance via Pipelining".

In option b, "Performance via Parallelism".

In option c, "Performance via Prediction".

In option d, "Make the Common Case Fast".

In option e, "Hierarchy of Memories".

In option f,  "Design for Moore’s Law".

In option g, "Dependability via Redundancy".

In option h, "Use Abstraction to Simplify Design".

Explanation:

Automotive assembly lines are Efficiency through pipelines.

The cable bridge suspension is used to Perform by Parallelism.  

The aircraft and navigation systems are designed to integrate and use through simulation wind information.  

The fast and the common Case is used to express lifts in the building.  

The Memory hierarchy library is used for the reserve desk.  

Extending the port area of a CMOS transistor to reduce Moore's Law Design for Moore's legislation switching sequence.

Increasing energy generation from the latest reactor technology dependability through redundancy. It enables the addition of electrical aircraft slingshots, which are electrically powered as opposed to the earlier steam models.  

It Constructs cars that depend on existing sensor systems, like automatic braking devices or clever speed control systems, that already have installed their monitoring system throughout the base vehicle by Using abstraction to ease the model.

7 0
4 years ago
Where does append add the new elements?
ZanzabumX [31]

Answer:

"Option 1: To the end of an array." is the correct answer.

Explanation:

The word "Append" means adding to the end of a document.

Appending means whatever new content is added, it is added at the end of the document or data structure.

Similarly,

Appending an array means adding new elements to the end of the array.

Hence,

"Option 1: To the end of an array." is the correct answer.

7 0
3 years ago
Other questions:
  • A cracked tone (reluctor) ring will often cause what type of problem
    13·1 answer
  • What Are the main reasons students take the SAT/ACT?
    15·1 answer
  • Powerpoint increased the weight of a line in ____ increments.
    13·1 answer
  • A parameter is a numerical measure that describes a characteristic of a sample. Choose One • 4 points True False
    6·1 answer
  • which of the following is the term used for a set of programs that acts as an interface between the applications that are runnin
    7·1 answer
  • Universal Containers has a requirement to integrate Salesforce with an external system to control record access. What option sho
    11·1 answer
  • You try to enter your name into a cell that accepts a numeric value. What error would you receive? A. #NAME B. #VALUE C. #REF D.
    14·2 answers
  • PROGRAM DESCRIPTION: In this assignment, you will write two complete C programs that will allow two players to play the game of
    12·1 answer
  • What refers to a set of instructions executed in order?
    6·1 answer
  • Time management is the ability to use time effectively.
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!