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
Can someone please tell me what I’m doing wrong ? Please and it’s due on Thursday!!
liberstina [14]

Answer:

Sure. In Unit test 5, it's looking for 1 instead of 0. You are returning 0 instead of 1.

0 requires 1 digit to express it and should therefore return 1.

In line 6, change the 0 to a 1.

8 0
2 years ago
What would you enter at the command prompt to start a new bourne again shell session?
butalik [34]

The answer is bash . The bash command opens a Bourne-again sheel (bash) session. It is the standard shell used in most Linux computers and it uses commands similar to a UNIX shell. Bash includes features such as:

1) Command completion when pressing the tab key.

2) Command history.

3) Improved arithmetic functions.

6 0
3 years ago
Which of these purchases is most likely to be paid for with a credit card
Vesna [10]

Answer:

plane ticket?

Explanation:

7 0
3 years ago
Describe how computer become <br> in the next 35 year
marin [14]
Well im going to say that it is going to be more advanced and easier to hack. Not only that but more and more people are going to be using it. You'll see ten year olds and five year olds using computers like they are professionals 
8 0
3 years ago
What does it mean to empty the cache?
Lina20 [59]
Cache are the temporary files that are downloaded onto your computer while going on a website, to clear this, you are getting rid of any of the cache. Not what you downloaded yourself, what the internet page downloaded for you.
6 0
3 years ago
Other questions:
  • All of the following except one are issues that should be covered in an AUP. Which one is the exception?
    5·1 answer
  • In 1997, two South Korean manufacturers of semiconductors, LG Semicon and Hyundai Electronics, were accused of selling dynamic r
    14·1 answer
  • How do Web browsers interact with URL/URIs to navigate the internet
    14·1 answer
  • A laptop computer is smaller than desktop computer. True or false
    10·2 answers
  • . Some countries lack physical resources, like computers or network connections, making it difficult to keep up with the technol
    8·2 answers
  • Complete the following Programming Assignment using Recursion. Use good programming style and all the concepts previously covere
    7·1 answer
  • The understanding of computer function?
    5·1 answer
  • An installation is:<br> please help asap
    11·1 answer
  • Which access method would be most appropriate if your manager gave you a special cable and told you to use it to configure the s
    6·1 answer
  • Why is a salt added to a password that is being stored in a database?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!