Reputation: 3
What I'm trying to do is get the program to display the highest and lowest value I put in and that corresponding month. I'm not trying to display the average or the sum. I am returned with an error and if anyone could look and tell me what I'm doing wrong, I'll greatly appreciate it.
def main():
year=[]
January = float(input('Please enter January rainfall: '))
February = float(input('Please enter February rainfall: '))
March = float(input('Please enter March rainfall: '))
April = float(input('Please enter April rainfall: '))
May = float(input('Please enter May rainfall: '))
June = float(input('Please enter June rainfall: '))
July = float(input('Please enter July rainfall: '))
August = float(input('Please enter August rainfall: '))
September = float(input('Please enter September rainfall: '))
October = float(input('Please enter October rainfall: '))
November = float(input('Please enter November rainfall: '))
December = float(input('Please enter December rainfall: '))
year.value((January, February, March, April, May, June, July, August, September, October, November, December))
def GetSmallestRainfall():
print('The minimum rainfall is', min(year))
lowest()
def GetLargestRainfall():
print('The most rainfall is', max(year))
highest()
main()
Upvotes: 0
Views: 1709
Reputation: 397
First off, I'd use a list to store your monthly rainfall values, not 12 different variables. You also never call GetSmallestRainfall()
or GetLargestRainfall()
from your main function, so they never run. Another point is that these functions are not in the scope of the main function, you need to pass them as arguments and return the minimum to print, like so:
def getValues():
months = ["January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
values = []
for i in range(12):
values.append(int(input("Please enter " + str(months[i]) + " rainfall: ")))
return values
def main():
rainfall = getValues()
print("The minimum rainfall was " + str(min(rainfall)))
print("The maximum rainfall was " + str(max(rainfall)))
main()
Upvotes: 2
Reputation: 58
You should be 'appending' to the list.
Upvotes: -1