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
System requirements that are important in determining if a software program will work on a computer are ____.
EastWind [94]
The RAM, System Storage ,CPU or GPU and Operating System.
5 0
3 years ago
Three different numbers need to be placed in order from least to greatest. For example, if the numbers are ordered 9, 16, 4, the
Anna11 [10]

Answer:A

Explanation:

3 0
3 years ago
What is your opinion on gaming? do you think it has more positive or negative impacts
joja [24]

Answer:

positive bc you can learn from them wwhat to do what not to do mistakes that you wont make in. real life

4 0
2 years ago
Read 2 more answers
Where should your two index fingers be when your fingers are rest.
PSYCHO15rus [73]

Answer: B : F and J

Explanation: Allows you to type without looking at keys and makes all the keys easily accessible

5 0
2 years ago
What is a hacker who breaks into other people's computer systems and may just look around or steal and destroy?
inessss [21]
A cyber gang or cyber theif
5 0
3 years ago
Read 2 more answers
Other questions:
  • Theresa is a certified teacher. She just had a baby and would like to stay home, but still wants to teach. Which career would be
    11·2 answers
  • Suppose that sum is an int variable. The statement sum += 7; is equivalent to the statement sum = sum + 7;
    7·1 answer
  • The computer output for integer programs in the textbook does not include reduced costs, dual values, or sensitivity ranges beca
    14·1 answer
  • Which of the following accessories would you use to create a drawing? A. Calculator B. Notepad C. Paint D. WordPad
    14·2 answers
  • 1. Who was able to complete the puzzle the fastest in Trial 1?
    15·1 answer
  • Write short notes about monitor printer and speaker​
    14·2 answers
  • Explain four sitting postures in a computer laboratory​
    9·1 answer
  • What is the output of the following code:
    10·1 answer
  • Pls help help me is good help me helping is very good
    10·1 answer
  • What was the name of the first computer, developed by charles babbage?.
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!