In: Computer Science
Design a program that lets the user enter the total rainfall for each of 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the months with the highest and lowest amounts.
This is my Pthon 3.8.5 code so far:
#Determine Rainfall Program for a 12 month Period
#It should calculate and output the "total yearly rainfall, avg
monthly rainfall, the months with highest and lowest amounts
#list of months in a year
months =
['January','February','March','April','May','June','July','August','September','October','November','December']
monthly_rain =[]
#functions to make calculations and inferences about rainfall
within YEAR.
def average():
return total(monthly_rain)/len(months)
def total():
return sum(monthly_rain)
def HAVG():
return max(monthly_rain)
def LAVG():
return min(monthly_rain)
#UserInput
year = str(input('What year is this from: '))
for month in months:
monthly_rain.append(input('Enter the total rainfall for' + month +
' in cm: '))
rainfall = [str(monthly_rain) for int in monthly_rain]
print(year + 'Rainfall Chart')
print('MONTH | AVG RAINFALL')
print(months[0] + ' | ' + rainfall[0])
print(months[1] + ' | ' + rainfall[1])
print(months[2] + ' | ' + rainfall[2])
print(months[3] + ' | ' + rainfall[3])
print(months[4] + ' | ' + rainfall[4])
print(months[5] + ' | ' + rainfall[5])
print(months[6] + ' | ' + rainfall[6])
print(months[7] + ' | ' + rainfall[7])
print(months[8] + ' | ' + rainfall[8])
print(months[9] + ' | ' + rainfall[9])
print(months[10] + ' | ' + rainfall[10])
print(months[11] + ' | ' + rainfall[11])
print('--------------------------------------')
print('YEAR AVG: ' + str(average))
print('HIGHEST AVG: ' + str(HAVG) +' LOWEST AVG: ' + str(LAVG))
months = ['January','February','March','April','May','June','July','August','September','October','November','December']
monthly_rain =[]
#functions to make calculations and inferences about rainfall within YEAR.
def average():
return sum(monthly_rain)/len(months)
def total():
return sum(monthly_rain)
#UserInput
year = str(input('What year is this from: '))
# maxx and minn are used to compare monthly rainfal with max and min rainfall
# to find the months with lowest and highest rainfalls
maxx=0
minn=1000000
# these are used to store the months with lowest and highest rainfalls
max_month=""
min_month=""
for month in months:
rain=float(input('Enter the total rainfall for ' + month + ' in cm: '))
monthly_rain.append(rain)
if rain>maxx:
maxx=rain
max_month=month
elif rain<minn:
minn=rain
min_month=month
# calculating total rainfall in the year
tot=total()
# calculating average of total rainfall in the year
avg=average();
print("\nTotal yearly rainfall is {:.2f}".format(tot))
print("\nAverage monthly rainfall is {:.2f}".format(avg))
print("\nThe month is highest rainfall is {}".format(max_month))
print("\nThe month is lowest rainfall is {}".format(min_month))
PLEASE LIKE THE SOLUTION :))
IF YOU HAVE ANY DOUBTS PLEASE MENTION IN THE COMMENT