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
Why do people still use Intel HD graphics for gaming?
pogonyaev
People usually do that because they can't afford a gpu or because they don't know anything about a gpu.
8 0
3 years ago
Figure out what this says:<br><br> ?driew tib a kool ti seoD
lisov135 [29]

Answer:

Does it look a bit weird?

5 0
3 years ago
How do I cancel a friend request?
dusya [7]

Answer:

By pushing cancel

Explanation:

It's simple

3 0
3 years ago
Read 2 more answers
Write a c++ program to input basic salary of an employee and calculate its Gross salary according to following
GREYUIT [131]
<h2>\large\bold{\underline{\underline{Program :}}}</h2>

#include<iostream>

using namespace std;

int main ()

{

float basic, gross, da, hra;

cout<<"Enter basic salary of an employee:";

cin>>basic;

if (basic <25000)

{

da = basic *80/100;

hra = basic *20/100;

}

else if (basic >=25000 & & basic<40000)

{

da = basic *90/100;

hra = basic *25/100;

}

else if (basic>=40000)

{

da = basic *95/100;

hra = basic *30/100;

}

gross = basic + hra + da;

cout<<"\n\t Basic Pay............" <<basic<<endl;

cout<<"\t Dearness Allowance..........." <<da<<endl;

cout<<"\t House Rent Allowance......" <<hra<<endl;

cout<<"\t Gross Salary............." <<gross<<endl;

cout<<"\t - - - - - - - - - - - - - - -" <<endl;

<h2>\large\bold{\underline{\underline{Output :}}}</h2>

Enter Basic Salary of an employee : 25000

Basic Pay : 25000

Dearness Allowance : 22500

House Rent Allowance : 6250

Gross Salary : 53750

<h2>\large\bold{\underline{\underline{Result :}}}</h2>

<h3>The Expected Output is archived</h3>
7 0
2 years ago
Can somebody help me?
Alika [10]
Are you signed in? if not then try to reset your device and see if you can get in there I hope this helped you if not plz let meh know :P 
5 0
4 years ago
Other questions:
  • you just bought a new hard drive for your computer to be used as a secondary hard drive to store all your files after installing
    5·1 answer
  • Jill edited James's document using Track Changes. James agrees with all of the edits and wants to incorporate them into his text
    6·1 answer
  • Which shape denotes a process to be carried out in a flowchart?
    7·2 answers
  • A _____ is a tool that helps you research information on the Internet.
    6·1 answer
  • 5.18 LAB: Output numbers in reverse Write a program that reads a list of integers, and outputs those integers in reverse. The in
    6·1 answer
  • Convert the following denary numbers into binary using 8-bit register:
    10·1 answer
  • A flowchart meeting is a process where members of the team analyze the design piece-by-piece to make sure it meets requirements
    15·1 answer
  • Help pleaseeeeeeeeeeeeeeeeee
    7·1 answer
  • Computers and their input and output devices require power to work and may have many power cords. What is the safest way to orga
    7·1 answer
  • 43
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!