有人可以帮我吗?我收到此错误:
'<' not supported between instances of 'builtin_function_or_method' and 'int'
我的代码还没有完成尝试运行一些测试的过程,因此无法通过此步骤:
# if it was to cold in the office remove number from list.
if input < 16:
total= len - 1
完整代码(到目前为止):
#Ask for temperature
print ("please enter the temperature")
Temp1 = input("enter temp: ")
Temp2 = input("enter temp: ")
Temp3 = input("enter temp: ")
Temp4 = input("enter temp: ")
Temp5 = input("enter temp: ")
Temp6 = input("enter temp: ")
Temp7 = input("enter temp: ")
Temp8 = input("enter temp: ")
#compute length of the list
length = len(Temp1+Temp2+Temp3+Temp4+Temp5+Temp6+Temp7+Temp8)
# if it was to cold in the office remove number from list.
if input < 16:
total= len - 1
#Calculate the percentage
percent= (len/total) * 100
#display the percentage the office was warm enough for the day
print percent here
答案 0 :(得分:1)
尝试一下:
temperatures = []
userIn = "placeholder"
while userIn != "": # we're doing what you were with your input, but now the user can input as many as is needed, being able to press enter without input to continue
userIn = float(input("Please enter the temperature. > ")) # I'm forcing float here as some people do record to one or two decimals. It also works for integers, too. It'll lead to a decimal in the final answer, though.
temperatures.append(userIn)
for item in temperatures: # Here, we're doing the check for being too cold.
if item < 16:
temperatures.remove(temperatures.index(item)) # This looks a little wonky, but it works.
average = 0
for item in temperatures: # This is needed due to the flexible length of the list of temperatures.
average += item
print("Average temp is "+str((average/len(temperatures))*100)) # I'd do the calculation in this statement, but you can do it beforehand if you want.