4,083 views
22 votes
22 votes
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.

User Guillaume Mohr
by
3.1k points

1 Answer

11 votes
11 votes

Solution :

def year):

inches
$=[]$


$\text{count} =0$

for range(year):

for j in range:

print("Enter the for the month in format(r))

count1

last = float(())

inches(last)

totalRainfall sum(inches)

totalMonths
$=$ count

return
$\text{totalMonths,totalRainfall}$

if __name__ '__main__':

year = int(input("Enter the
$\text{number}$ of years (
$\text{Greater than 0}$):\\"))

print("For
$\text{year

while year :

year = int(("Enter of years ():\\"))

print("For
$\{\}$ months"
$.\text{format}$(totalMonths))

print("Total rainfall: ",
$\text{totalRainfall}$)

print("Average monthly
$\text{rainfall:}$",
$\text{totalRainfall/totalMonths}$)

User Nirel
by
3.0k points