Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

2.7 Identify how privacy legislation impacts employees.

Answered: 1 week ago