Answer:
In Python:
year = int(input("Years: "))
while year<1:
year = int(input("Invalid. Enter 1 or greater: "))
total = 0
for i in range(1,year+1):
for j in range(1,13):
month = int(input("Year "+str(i)+", Month "+str(j)+": "))
while month<0:
month = int(input("Invalid. Enter 0 or greater: "))
total+=month
ave = total/(12*year)
print("Months: "+str(12 * year))
print("Total: "+str(total))
print("Average: "+str(ave))
Step-by-step explanation:
This gets the number of years
year = int(input("Years: "))
This loop validates the number of years
while year<1:
year = int(input("Invalid. Enter 1 or greater: "))
This initializes total to 0
total = 0
This iterates through the years
for i in range(1,year+1):
This iterates through the month of each year
for j in range(1,13):
This gets the rainfall for each month
month = int(input("Year "+str(i)+", Month "+str(j)+": "))
This loop validates the amount of rainfall
while month<0:
month = int(input("Invalid. Enter 0 or greater: "))
This calculates the total rainfall
total+=month
This calculates the average rainfall
ave = total/(12*year)
This prints the number of month
print("Months: "+str(12 * year))
This prints the calculated total amount of rainfall
print("Total: "+str(total))
This prints the calculated average amount of rainfall
print("Average: "+str(ave))