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
                                                       HELP PLEASE 
Marina CMI [18]
Your answer should be mode







5 0
2 years ago
Read 2 more answers
One reason to buy a home instead of rent a home is:
vazorg [7]
A is the correct Answer

7 0
3 years ago
How do you add text to a blank slide layout?
melisa1 [442]

The answer is B; Draw a text box and enter text

By default, we add text to a PowerPoint slide by typing it directly into a placeholder. However, you can use a text box to enter text into a blank slide or outside the placeholders. To add text on a blank slide click on the insert menu and select the Text box option. Click and hold down your mouse button while you drag the mouse. You will then clink inside the text box and starting typing.


6 0
3 years ago
Read 2 more answers
What happens when your project is rendered?
jok3333 [9.3K]

Answer:

B

Explanation:

when your rendering video project your computer is processing all the data that goes into creating images you experience video rendering every time you look at your computer the images on your screen has all been rendered to produce the website photo or video you are looking at

4 0
2 years ago
What is the importance of technology in your life?Explain.
Ghella [55]

technology has been very important in my life because, it helps me with my daily struggles, helps with stress (social media), makes everything easier, also creates a more efficient way of learning and much more.

although this should be answered with your own thoughts and opinions, I provided mine if in any case that it helps

8 0
2 years ago
Other questions:
  • When recording data on a multiple-disk storage system, should we fill a complete disk surface before starting on another surface
    6·1 answer
  • Which principle of CSR requires that a business state facts fully and accurately?
    8·1 answer
  • HELP URGENT
    12·2 answers
  • Explain why an IT department and a user support group may disagree about the responsibility for the development of end-user appl
    8·1 answer
  • PLZ help
    5·1 answer
  • The first step when entering data is _
    6·1 answer
  • What happens when you apply a theme to a form?
    14·1 answer
  • Virus warning don’t go on bit l y links it’s a virus
    12·2 answers
  • which one of the following will reach every element in the array a? 1. for(int i = 0; i <= a.length; i++) 2. for(int i = 0; i
    10·1 answer
  • Edit the program provided so that it receives a series of numbers from the user and allows the user to press the enter key to in
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!