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
Which disk drive type contains a magnetic HDD with onboard flash memory serving as a non-volatile cache?
Shkiper50 [21]

Answer:

SSHD - Solid State Hybrid Drives

Explanation:

SSHD - Solid State Hybrid Drives -

Hard disk refers to a storage form of device , which uses uses the combination of the fast storage medium like the solid - state drive along with the very higher - capacity hard disk drive .

In the solid state hybrid drives , the combination of the onboard flash memory and the magnetic HDD , which is less expensive than the SSD.

Hence , from the given information of the question ,

The correct term is SSHD - Solid State Hybrid Drives  .

5 0
3 years ago
What is the basic unit for storing data in exel
vaieri [72.5K]
<span>the basic unit for storing data in exel is </span><span>The intersection point between a column and a row is a small rectangular box known as a cell. A cell is the basic unit for storing data in the spreadsheet. Because an Excel spreadsheet contains thousands of these cells, each is given a cell reference or address to identify it.</span>
7 0
4 years ago
What is a two content slide​
daser333 [38]

Answer:

Slide layouts define containers, positioning, and formatting for all of the content that appears on a slide. Placeholders are the containers in layouts that hold such content as text (including body text, bulleted lists, and titles), tables, charts, SmartArt graphics, movies, sounds, pictures, and clip art.

Explanation:

5 0
3 years ago
Once a virus has been removed by your anti-virus program, all traces of it are gone from your computer.
pychu [463]
Im pretty sure that is false
5 0
3 years ago
Consider a smart array that automatically expands on demand. (Like the java.util.ArrayList.) It starts with some given initial c
elena-14-01-66 [18.8K]

Answer:

Total unit of work required is 1019 units.

Solution:

As per the question:

Initial capacity = 100

On each expansion 50 is added to the present capacity.

Now,

Work done required in addition  of 1000 items = 1000 unit

No. of times there is a need for the allocation of a new Array is given by:

n = \frac{1000 - 100}{50} = 18

We know that:

On addition of 101th element it expands from 100 to 150

On addition of 151st element it expands from 150 to 200 and so on till

On addition of 951st element it expands from 950 to 1000

Now,

For an array of 100 size - 1 for initial allocation.

Therefore, total work done is  given by:

W = 1000 + \frac{1000 - 100}{50} + 1 = 1019\ units

4 0
4 years ago
Other questions:
  • Terry is building a Web site and wants to have three main links called Home, Product Info, and Contact Us. She will create a hie
    9·1 answer
  • What is the difference between C and C++. If I know C, will it be hard to lean C++?
    15·1 answer
  • Examine the following algorithm.
    9·1 answer
  • What is the unofficial name given to the culture that has emerged from living in the age of digital media, whereby people are fr
    7·2 answers
  • Usually written in block style with body text aligned along the left margin
    5·2 answers
  • What file name would allow you to easily find and edit your document later in Word Online?
    14·2 answers
  • ก
    6·2 answers
  • Is the ability to choose the start and finish times, but they must complete a full day’s work
    8·1 answer
  • List resource you can utilize if you are experiencing technology issued
    5·1 answer
  • True or false?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!