我正在尝试进行一个非常基本的迷你测验,但是我一直遇到一个问题,其中只有我的else语句得到了满足,我不确定为什么?
userSleep = [input("Please enter 1 or 2 to answer the question. ")]
if userSleep == 2:
print("Thank you for your answer")
time.sleep(1)
print("What would you say stops you from getting more sleep?")
print("[1.] Social Media")
time.sleep(.25)
print("[2.] On-demand TV services (i.e Netflix, Crunchyroll, YouTube etc.)")
time.sleep(.25)
print("[3.] Medically diagnosed insomnia")
time.sleep(.25)
print("[4.] School assignments/coursework")
time.sleep(.25)
print("[5.] Other")
time.sleep(.5)
userHabits = [input("Please enter a number corresponding one of the options above to answer the question. ")]
print("Thank you for your answer")
time.sleep(1)
break
clear()
elif userSleep == 1:
print("Thank you for your answer")
time.sleep(1)
break
clear()
else:
print("Please input either a 1 or 2")```
I'm using Python 2.7
答案 0 :(得分:0)
将userSleep = [input("Please enter 1 or 2 to answer the question. ")]
更改为userSleep = int(input("Please enter 1 or 2 to answer the question. "))