我的while语句有点古怪,我不知道怎么了

2024-05-23 14:29:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码不起作用,我不知道发生了什么。问题是,当我第一次输入“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

Tags: oftoyouyourgetifoutprint