so i had some homework to write a quick program that was relatively easy but for some reason i have an error in the input everything works except listing the months with the array command when inputting the precipitation for that month, i thought i had everything right, and if i take ,months[index] out everything works fine, but i need it to list the month per the months array via the index, is there some reason this cannot work or did i just make a simple error or what? the error is in line 23 if u cant see it right away...
Code
months=[""]*12
months[0] = "January"
months[1] = "February"
months[2] = "March"
months[3] = "April"
months[4] = "May"
months[5] = "June"
months[6] = "July"
months[7] = "August"
months[8] = "September"
months[9] = "October"
months[10] = "November"
months[11] = "December"
rain_fall_array=[0.0]*12
index = 0
total_precip = 0.0
avg_precip = 0.0
lowest_precip = 0.0
highest_precip = 0.0
high_month_name = ""
low_month_name = ""
for index in range (0,12):
rain_fall_array[index]=float(input("Please enter the total Precipitation in Inches for ",months[index]))
total_precip = total_precip+rain_fall_array[index]
print ("Precipitation for",months[index],"is : ",rain_fall_array[index])
index = index+1
print ("==================================================\n")
avg_precip = total_precip/12
print ("The Average Precipitation for the year was: ",avg_precip,"inches")
print ("The Total Precipitation for the year was: ",total_precip,"inches")
index = 0
lowest_precip = avg_precip
while index < 12:
if rain_fall_array[index]>avg_precip:
if rain_fall_array[index]>highest_precip:
highest_precip = rain_fall_array[index]
high_month_name = months[index]
elif rain_fall_array[index]<lowest_precip:
lowest_precip = rain_fall_array[index]
low_month_name = months[index]
index = index+1
print ("==================================================")
print ("The highest Precipitation was in ",high_month_name," which was ",highest_precip," inches")
print ("The lowest Precipitation was in ",low_month_name," which was ",lowest_precip," inches")
This post was edited by Drakwen on Jul 7 2015 08:14am