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
You have recently installed Windows Server 2019 Desktop Experience on a server. Your manager informs you that he needs to extens
Korolek [52]

To meet the manager requirement, you need to format the server, then after that install Server Core. This process is now followed by rebooting the server in the Server Core mode.

<h3>How do you install a Windows server?</h3>

Whenever you want to install Windows Server by using setup wizard settings, you have the choice of installing Server Core or Server with a graphical user interface known as the Desktop Experience installation method.

Since the GUI is not usually installed with Server Core; you control the server via the command line by using:

  • PowerShell,
  • The Server Configuration tool (SConfig), or
  • Remote methods. 

Now, if your manager informs you that he needs to extensively use the command line and PowerShell but not the use of graphical interface, the best way to meet the requirements are:

  • Format the server and install server core
  • Reboot the server in the Server Core mode

Learn more about Windows server installation here:

brainly.com/question/26175904

5 0
2 years ago
Electricity is moved from place to place a long __________​
nexus9112 [7]

Answer:

current of electricity

Explanation:

hope it will help full to you

6 0
2 years ago
Read 2 more answers
A technician wants to limit access to a group of folders and is using Group Policy to prevent the users in the sales department
Mashcka [7]

Answer:

d. The technician should be setting NTFS permissions instead of using Group Policy.

Explanation:

NTFS (New Technology File System) permissions run on drives formatted with NTFS.Under NTFS permissions, individual users are granted permission at the Windows logon and so in this way local users and network users are affected, affecting each user from wherever he may be connecting from. In the example above using NTFS permissions would solve the problem of file system among departments .

4 0
2 years ago
Which one of the following word processing features saves you the most time when keying a document?
drek231 [11]
C) find and replace which finds the words you want to replace in a document and replaces them to whatever you specify
3 0
3 years ago
Visual-verbal synergy has nothing to do with text, but solely with images used in a design.
Ilia_Sergeevich [38]
I think it is true (A) 
3 0
3 years ago
Other questions:
  • In the space below, write the formula that needs to be added to the blank cells under the fourth column of the table.
    13·1 answer
  • Which one of the following parts of a universal motor does not move? A. The armature B. The field coil C. The shaft D. The commu
    5·1 answer
  • The clear emergence of a leader and the development of group norms and cohesiveness are the key indicators of the ________ stage
    6·1 answer
  • i need to also do a algorithm where if the total is a even number 10 points are added to the score and if the total is odd then
    11·1 answer
  • Match each role to the corresponding web development task.
    14·1 answer
  • Computer technology has changed our lives write of a least five ways to show how this is so​
    15·1 answer
  • 2.
    11·1 answer
  • How to use access?<br> like working in access and bringing tables and stuff
    5·1 answer
  • Describe from an administrator perspective what is necessary to prepare a storage device for access by a user.
    14·1 answer
  • You have an audio that contains one pause for 0.2 seconds and another one for 0.6 seconds. When do you need to create a new segm
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!