该程序应该有两个输入,度的单位是F或C,然后是温度,然后打印出水的状态。无论我为C投入多少(除了1000),我都得到答案是液体,从不冷冻或气体。这是我的代码:
print("Do you use Fahrenheit (F) or Celcius? (C)")
degreeUnit = (input("Enter F or C:")).upper()
temp = int(input("What is the temperature of the water?"))
if degreeUnit == "F" and temp <=32: #checking if unit is F and if water is frozen
print("The water is frozen.")
elif degreeUnit == "F" and temp >= 212: #water freezes at 32F is gas at 212 is it gas?
print("The water is a gas")
elif degreeUnit == "F" and temp >=33 or temp <=211:
print("The water is a liquid.")
elif degreeUnit == "C" and temp <=0: #water freezes at 0C
print("The water is frozen.")
elif degreeUnit == "C" and temp >=100: #water is gas at 100C
print("The water is a gas.")
elif degreeUnit == "C" and temp >=1 or temp <=99:
print("The water is a liquid.")
else:
print("Please try again, something went wrong.")
input()
我觉得自己缺少明显的东西,但是我不断地阅读它,看不到我在做什么错。任何帮助表示赞赏。
如果您经常进水,则应检查是否有液体。真的是您想要的吗?(提示,不是)。检查最后一个elif语句的逻辑,您对于'F'也有相同的错误(自由单位:-D)
您可能还会发现,加入括号以查看您的逻辑会有所帮助:
a=False
b=True
c=True
a and b or c
>>>True
a and (b or c)
>>>False
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句