How do I find the maximum value from this array and not get the TypeError: 'int' object is not iterable?


#1
MiddayTemperature=[]
MidnightTemperature=[]
MiddayTempTotal = 0
MidnightTempTotal = 0
MiddayTempAverage = 0
MidnightTempAverage = 0
HighestMiddayTemp = 0
HighestMidnightTemp=0

for i in range (3):
    MiddayTemp = input ("Enter new temperature for the midday temperatures of the month in order, starting with day 1")
    MiddayTemperature.append(MiddayTemp)
    MiddayTempTotal = MiddayTempTotal + MiddayTemp

print MiddayTemperature
print MiddayTempTotal

for i in range (3):
    MidnightTemp = input ("Enter new temperature for the midnight temperatures of the month in order, starting with day 1")
    MidnightTemperature.append(int(MidnightTemp))
    MidnightTempTotal = MidnightTempTotal + MidnightTemp

print MidnightTemperature
print MidnightTempTotal

MiddayTempAverage = MiddayTempTotal/30
MidnightTempAverage = MidnightTempTotal/30

print MiddayTempAverage
print MidnightTempAverage


max(MiddayTempTotal)

#2

MiddayTempTotal is a integer, max should be called on array to get the highest value from an array


#3

So how can I find the maximum value from an array???


#4

I guess you might want to do this:

MiddayTemperature=[]
MidnightTemperature=[]
MiddayTempTotal = 0
MidnightTempTotal = 0
MiddayTempAverage = 0
MidnightTempAverage = 0
HighestMiddayTemp = 0
HighestMidnightTemp=0

for i in range (3):
    MiddayTemp = input ("Enter new temperature for the midday temperatures of the month in order, starting with day 1")
    MiddayTemperature.append(MiddayTemp)
    MiddayTempTotal = MiddayTempTotal + MiddayTemp

print MiddayTemperature
print MiddayTempTotal

for i in range (3):
    MidnightTemp = input ("Enter new temperature for the midnight temperatures of the month in order, starting with day 1")
    MidnightTemperature.append(int(MidnightTemp))
    MidnightTempTotal = MidnightTempTotal + MidnightTemp

print MidnightTemperature
print MidnightTempTotal

MiddayTempAverage = MiddayTempTotal/30
MidnightTempAverage = MidnightTempTotal/30

print MiddayTempAverage
print MidnightTempAverage

# MidnightTemperature is a list with 3 numbers
print max(MidnightTemperature)

MidnightTemperature is a list, so you can call max() on it:

>>> max( [1, 10, 100] )
100

How would you call max() on a single integer? MiddayTempTotal is a single number so you there aren’t max or min value from it.