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.

Respuesta :

Solution :

def year):

  inches [tex]$=[]$[/tex]

 [tex]$\text{count} =0$[/tex]

  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 [tex]$=$[/tex]  count    

  return [tex]$\text{totalMonths,totalRainfall}$[/tex]

 

if __name__ '__main__':

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

print("For  [tex]$\text{year",year,":")}$[/tex]

while year :

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

print("For [tex]$\{\}$[/tex] months"[tex]$.\text{format}$[/tex](totalMonths))

print("Total rainfall: ",[tex]$\text{totalRainfall}$[/tex])

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