我正在学校里做一个项目,它包含一些小挑战,但是在此上,一旦输入答案,它就不会显示任何内容:
sleepHours=float(input("how many hours of sleep did you have last night?"))
if sleepHours == 0-4:
print ("back to bed!")
elif sleepHours == 5-7:
print ("not bad...")
else:
print ("Well Done!")
答案 0 :(得分:2)
与float相比无法按您认为的那样工作...
您的代码应为
if 0 <= sleepHours <= 4:
...
您的代码有效执行的操作是将sleepHours
与0-4
进行比较。 (与第二个比较类似)。
答案 1 :(得分:0)
sleepHours=float(input("how many hours of sleep did you have last night?"))
if 0 <= sleepHours <= 4:
print ("back to bed!")
elif 5 <= sleepHours <= 7:
print ("not bad...")
else:
print ("Well Done!")