Your current loop confuses temp
with x
a few places. You need to be consistent about them because they're different types (temp
is a string and x
is a float
). Here's a fixed version of the code, with a few other fixes, like testing for an empty string and providing an initial value for avg
:
sums = 0.0
count = 0
heating = 0
cooling = 0
avg = 0 # need an initial value for this, in case the first input is empty!
temp = input("enter a number, <enter> to quit: ") # temp is always a string
while temp: # equivalent to testing temp != ""
x = float(temp)
sums = sums + x
count = count + 1
avg = sums/count
if avg < 60:
if x < 60: # compare to x here, not temp
heating = heating + 1
if avg > 80:
if x > 80: # here too
cooling = cooling + 1
temp = input("enter a number, <enter> to quit: ") # moved this to the end of the loop
print(avg, heating, cooling)