【发布时间】:2021-09-12 19:07:17
【问题描述】:
所以我想创建一个用户输入的不同温度的列表,然后打印出最高温度。我使用了以下解决方案,效果很好:
tempList = []
for i in range(0, int(input("How many temps? "))):
temp = (float(input("Input a temp: ")))
tempList.append(temp)
print("Temps are: ", tempList, "and the max temp is:", max)
但是,我正在尝试通过循环列表来使用另一种解决方案:
tempList = []
for i in range(0, int(input("How many temps? "))):
temp = (float(input("Input a temp: ")))
tempList.append(temp)
print(max(tempList))
max = 0.00
for temp in range(0, len(tempList)):
if temp > max:
max = temp
print("Temps are: ", tempList, "and the max temp is:", max)
它工作正常,直到打印出“max”结束。当我输入 36.5 或类似的东西时,它给了我 2。我做错了什么?
【问题讨论】: