Write a Python program (rainfall.py) to collect data and calculate the average rainfall over a period of years. The program should 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.

Answers

Answer 1

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


Related Questions

how can we achieve an effective communication with other people​

Answers

Just be yourself!
Explanation.......

Arnie is planning an action shot and wants the camera to move smoothly alongside his running characters. He is working on a tight budget and can’t afford expensive equipment. What alternatives could you suggest?

Mount the camera on a wagon, wheelchair, or vehicle and move it next to the characters.
Rearrange your script so you don’t need to capture the motion in that way.
Try running next to the characters while keeping the camera balanced.
See if you can simulate the running with virtual reality.

Answers

Camera and wagon are answer

((PLEASE HELP ME)) i need to get all my school work done before thursday
------------- are used to navigate between pages and Web sites.

Question 1 options:

Transitions


Animations


Hyperlinks


None of the above

Answers

Answer:

none of the above

Explanation:

Web navigation refers to the process of navigating a network of information resources in the World Wide Web, which is organized as hypertext or hypermedia. The user interface that is used to do so is called a web browser.

9. Which of the following is the
leading use of computer?​

Answers

Complete Question:

What is the leading use of computers?

Group of answer choices.

a. web surfing.

b. email, texting, and social networking.

c. e-shopping.

d. word processing.

e. management of finances.

Answer:

b. email, texting, and social networking.

Explanation:

Communication can be defined as a process which typically involves the transfer of information from one person (sender) to another (recipient), through the use of semiotics, symbols and signs that are mutually understood by both parties. One of the most widely used communication channel or medium is an e-mail (electronic mail).

An e-mail is an acronym for electronic mail and it is a software application or program designed to let users send texts and multimedia messages over the internet.

Also, social media platforms (social network) serves as an effective communication channel for the dissemination of information in real-time from one person to another person within or in a different location. Both email and social networking involves texting and are mainly done on computer.

Hence, the leading use of computer is email, texting, and social networking.

List 3 clinical tools available in the EHR and discuss how those benefit the patient and/or the practice

Answers

Thor Odin and Aries the threes listed powerful

What is a key consideration when evaluating platforms?

Answers

Answer:

The continuous performance of reliability data integrity will lead to the benefit and profit of the platform's regular structure changes. Cleanliness in the platform whereas addresses the straightforward structure of task performance and adequate data integrity.

Under which menu option of a word processing program does a star appear?
A star appears under the
menu of the word processing program.

Answers

UNDER THE MENU OPTION INSERT.

Answer:

shapes

Explanation:

Plato got it correctly

Other Questions
Mrs smith and i went to the shop to creme eggs at 23p each & kinder eggs at 47 peach in bulk. We bought 141 eggs altogether & it came to 48.51 how many creme eggs did we buy ? PLEASE I NEED HELP CLICK ON THIS IMAGE 3/4x < 33Solve the inequality What term is used to describe words with similar meanings?antonymscontext cluesdefinitionssynonyms i need help with this Narrative paragraphThe Most Frightening Moment in My Life120-150 words HELP I NEED HELP ASAP HELP I NEED HELP ASAP HELP I NEED HELP ASAP HELP I NEED HELP ASAPHELP I NEED HELP ASAP HELP I NEED HELP ASAP HELP I NEED HELP ASAP HELP I NEED HELP ASAP In VWX, w = 770 inches, x = 520 inches and V=81. Find the area of VWX, to the nearest square inch. Gandhis nickname, Mahatma, meansenlightened one.great soul.happy one.peaceful soul. Boris runs 9 miles in 57 minutes.How many miles does he run per minute?(round to the nearest hundredth) State if the triangle is acute, obtuse, or right Which expression is equivalent to 5(n + 7)? the roles of internal auditors What is the total surface area?? PLEASE HELP THIS IS A QUIZ IM SO CONFUSED Sharks protect producers (sea grasses)byacting as abiotic limiting factorsallowing populations of sea grass consumers(organisms that eat sea grass) to growuncontrollablykeeping the populations of sea-grass.consumers in check (controlled) What led to Indian independence from Great Britain? Solve the proportion.1015a24a = [?]help please I will give you brainliest!! Please help! Spanish Conjugations!What are the conjugations of SER and ESTAR in Spanish? please help me lol. The figure on the left is reflected using line l to form the image on the right. Use the information in the original figure to label the corresponding parts inthe image.Ite!Ite2.2IteIteO1433.20Ite1084Ite639OoIteIte How could Hoover have better handled the Great Depression in his 3 years as president during the Depression?