我的代码无效,我不知道发生了什么。问题是当我输入" Y"第一次,它仍然说"请输入有效的输入"我需要再次进入第二次才能工作。
if getoutofbed == "y":
outofbed = 1
print("You chose to get out of bed.")
elif getoutofbed == "n":
outofbed = 2
print("Your mom disregards your choice and screams at you to get out of bed. Listening to your mother, you step off the ledge of your resting place.")
print(" .@@@@,")
print(" aa`@@@,",name.upper(),"I DONT CARE IF YOU DONT WANNA GET UP!")
print(" = `@@@ GET UP!")
print(" )_/`@'")
print(" / || @")
print(" | || @")
print(" /~|| `")
print(" /__W_/")
print(" |||")
print(" _|||")
print(" ((___)")
print("")
print("")
while outofbed != 1 or 2:
print("Please enter a valid input.")
print("")
print("")
getoutofbed = input("Choose to get out of bed? Y/N").lower()
print("")
print("")
if getoutofbed == "y":
print("You chose to get out of bed.")
break
elif getoutofbed == "n":
print(" .@@@@,")
print(" aa`@@@,",name.upper(),"I DONT CARE IF YOU DONT WANNA GET UP!")
print(" = `@@@ GET UP!")
print(" )_/`@'")
print(" / || @")
print(" | || @")
print(" /~|| `")
print(" /__W_/")
print(" |||")
print(" _|||")
print(" ((___)")
break
答案 0 :(得分:2)
您需要更改while循环语句。
即使outofbed != 1
评估为False
,2
也会评估为True
,因为它是一个“真实”值。将其更改为:
while outofbed != 1 and outofbed != 2:
希望这有帮助