I have been messing with this program for my class for days now. I can get the program to run fine....I can get it to return highest value in list but i need it to return the month it occurs in.
Here is the exercise as it appears in my book:
3. Rainfall Statistics
Design a program that lets the user enter the total rainfall for each of the 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts.
and here is the code I have written so far...i have tried everything I can find about list bust cant get it to do what I want:
# Chapter 8 Excercise 3
# This program will calculate the total rainfall for a year as well as the
# average in inches. Also it will display
# the months with the highest and lowest amounts.
print 'This program will calculate the total rainfall for a year as well as the'
print 'average in inches. Also it will display'
print 'the months with the highest and lowest amounts.'
print # This is for spacing output
def main ():
rainfall = rainInput ()
totalRain = totalRainfall (rainfall)
average_Rainfall = averageRainfall (totalRain)
highestMonth = highestMonthNumber (rainfall)
print #this is for spacing output
print 'The total rainfall for the year was: ' +str(totalRain) + ' inche(s)'
print #this is for spacing output
print 'The average rainfall for the year was: ' +str(average_Rainfall) +\
' inche(s)'
print #this is for spacing in output
print 'The highest amount of rain was in' , highestMonth
def rainInput ():
rainfall = ['January','Febuary','March','April','May','June','July','August'\
,'September','October','November','December']
month = 0
while month < len(rainfall):
rainfall[month] = input ('Please enter the amount for month ' + str\
(month + 1) + ': ')
month = month + 1
return rainfall
def totalRainfall (rainfall):
totalRain = 0
month = 0
while month < len(rainfall):
totalRain = rainfall[month] + totalRain
month = month + 1
return totalRain
def averageRainfall (totalRain):
average_Rainfall = totalRain / 12
return average_Rainfall
#Cant figure out this module
def highestMonthNumber (rainfall):
month = ['January','Febuary','March','April','May','June','July','August'\
,'September','October','November','December']
highestMonth = max(rainfall[])
return highestMonth
main ()
PLEASE help this is do by 11:30 and it is already late......