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
The objects that you place on master pages are called _____.
Studentka2010 [4]
The answer to this is A.
3 0
3 years ago
Demote the "Arrive and leave at the same time each day." List item, and then promote the "Respect" list item.
garri49 [273]

Answer:

Dear

<h3>You should wear something professional. A tie, suit, classy dress, heels. You are more likely to be hired if you make it look like you take pride in your appearance. Also, depending on what kind of job you are applying for, the outfits can vary as well.</h3>

Explanation:

Black is too formal for interviews, and earth tones are too casual. Two-button suits are the professional standard.

7 0
3 years ago
What type of activities are performed with the help of the software used in hospitals?
faust18 [17]

Answer:

Xrays, Ultrasounds, managing patient records, communicating with colleagues, etc.

7 0
3 years ago
Read 2 more answers
You type a complex formula in cell A20. You would like to make the same calculation in cells B20 through H20. To be efficient, y
fomenos

Answer:

Use autofill

Explanation:

In excel "autofill" is used to fill data in cells, which follows the pattern or logic applied in other cells. To apply same calculation of A20 in B20 to H20, we use autofill technique. Instead of copy pasting, or manually entering the complex formula this method is more suitable.  

4 0
3 years ago
The following code would include _______.
julia-pushkina [17]

Answer:

Option d is the correct answer for the above question

Explanation:

  • The above question asked about the result of the above question code, which has the query of two tables and their primary key is matched in the where class.
  • The Customer_T table has a primary key "CustomerID" and the Order_T has a foreign key "Customer_ID" and that both are matched in the where clause.
  • So the above query fetches that result in which the records match both the table. Hence Option d is the correct answer for the above question while the other is not because another option is not to get by the result of the above query.
8 0
3 years ago
Other questions:
  • What is a major plastics engineering project that is going on right now in Arizona?
    9·1 answer
  • A local area network works as a ____ network in that clusters of workstations are connected to a central point (hub or switch) t
    6·1 answer
  • This assignment is to read from an input file and process the data for a group of people. Your program calculates the interest a
    5·1 answer
  • If someone receives a shock, or a piece of equipment is throwing sparks or arcing you should try to pull them away from the sour
    7·1 answer
  • "The effectiveness of memory retrieval is directly related to the similarity of cues present when the memory was encoded to the
    11·1 answer
  • We already know that we can create a lunar lander application of the pipe-and-filter architecture style from three independent J
    6·1 answer
  • You are a Data Scientist at Anthem Blue Cross Blue Shield. You want to check if a patient will develop diabetes. Please write th
    5·1 answer
  • What are styles? built-in conditional formatting rules formatting applied with the Format Painter defined combinations of format
    15·2 answers
  • Brainly Question
    14·2 answers
  • unlike the barcode-based tracking system, a radio frequency identification system offers a .
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!