Write a python program that allows the user to 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, and the months with the highest and lowest rainfall amounts.

Data:

January 7.9 inches

February 10.1 inches

March 3.4 inches

April 6.7 inches

May 8.9 inches

June 9.4 inches

July 5.9 inches

August 4.1 inches

September 3.7 inches

October 5.1 inches

November 7.2 inches

December 8.3 inches

Respuesta :

Answer:

The program is attached, one file is using a fuction and one doing same calculations without a fuction  

Explanation:

Please take a look to the files, below is a copy:

months=['january','february','march','april','may','june','july','august','september', 'october','november','december']

monthly_rainfall=[]

for month in months:

   parsed=False

   while not parsed:  #This will keep prompting the user for input until parsed     is True which will only happen if there was no exception.

       try:

           rainfall=float(input("Enter rainfall in inches for the month {}: ".format(month)))

           parsed=True

       except ValueError:

           print('Your input is invalid')

   monthly_rainfall.append(rainfall)

print("Total amount of rainfall:{}".format( sum(monthly_rainfall)))

print("Average monthly rainfall:{}".format( sum(monthly_rainfall)/len(monthly_rainfall)))

print("Highest amount of rainfall:{}".format( max(monthly_rainfall)))

print("Lowest amount of rainfall:{}".format( max(monthly_rainfall)))

Ver imagen dogacandu
Ver imagen dogacandu

The program is an illustration of loops

The program in Python, where comments are used to explain each line is as follows:

#This initializes all months of the year

months=['January','February','March','April','May','June','July','August','September', 'October','November','December']

#This initializes a list for the amount of rainfall each month

monthly_rainfall=[]

#The following iteration gets input for the amount of rainfall each month, and appends it to the list

for month in months:

       rainfall=float(input("{}: ".format(month)))

       monthly_rainfall.append(rainfall)

#The next four lines print the required outputs        

print("Total : %.2f" % ( sum(monthly_rainfall)))

print("Average : %.2f" % ( sum(monthly_rainfall)/len(monthly_rainfall)))

print("Highest : %.2f" % ( max(monthly_rainfall)))

print("Lowest : %.2f" % ( min(monthly_rainfall)))

Read more about loops at:

https://brainly.com/question/14284157