Question: For the below code, I am able to enter the rainfall values for each month and able to display the total and average rainfall. When

For the below code, I am able to enter the rainfall values for each month and able to display the total and average rainfall. When I use the minRainfall = min(newList) and maxRainfall = max(newList) then the output is 2.0 for both. I am trying to display the minimum and maximum rainfall along with the month.

##Write a program that allows the user to enter the total rainfall for each ##of the 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.

def main(): months = ['January', 'February' , 'March' , 'April' , 'May', 'June', 'July',\ 'August' , 'September', 'October', 'November', 'December']

total = 0

for months in list(months): newList = [] amount = float(input("Enter the total monthly rainfall in inches: ")) newList.append(amount)

for values in list(newList): total += values print(months, newList) print("Updated rainfall total for the year:" ,format(total, '.3f')) average = total / 12 print("The average rainfall for the year is" ,format(average, '.3f'))

minRainfall = min(newList) ##indexMinMonth = newList.index(min(newList)) print(str(minRainfall)) maxRainfall = max(newList) ##indexMaxMonth = newList.index(max(newList)) print(str(maxRainfall)) main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!