0

My code is not working, and I'm not sure what is going on. The problem is when I input "Y" the first time, it still says "Please enter a valid input" and I need to re-enter a second time for it to work.

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

1 Answers1

2

You need to change your while loop statement.

Even when outofbed != 1 evaluates to False, 2 will evaluate to True because it is a "truthy" value. Change it to this:

while outofbed != 1 and outofbed != 2:

Hope this helps

Brian Howell
  • 67
  • 2
  • 13