我的代码不起作用,我不知道发生了什么。问题是,当我第一次输入“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
您需要更改while循环语句。你知道吗
即使
outofbed != 1
求值为False
,2
也会求值为True
,因为它是一个“真实”值。更改为:希望这有帮助
相关问题 更多 >
编程相关推荐