-2

hello I am new to python coding and am wondering why whatever is inputted it results in the if statement.

def opnbx():
    opn = input("in frount of you is a box do you open it? ")
    if opn == "yes" or "Y" or "y" or "Yes":
        print("you open the box")
    elif opn == "no" or "No" or "N" or "n":
        print("you ignore the box and move on")
    else:
        print("please repeat...")
        opnbx()
opnbx()
  • you're not using the `or` correctly. It always enters the first condition because it always evaluates to true since `"Y"` as a boolean is considered true. If you have more than one condition in the same statement, you have to do it like this: `if opn == "yes" or opn == "y" or ...` – Shinra tensei Jan 19 '18 at 08:19

1 Answers1

0

Try this:

def opnbx():
    opn = input("in frount of you is a box do you open it? ")
    if opn in ("yes", "Y", "y", "Yes"):
        print("you open the box")
    elif opn in ("no", "No", "N", "n"):
        print("you ignore the box and move on")
    else:
        print("please repeat...")
        opnbx()
opnbx()
Keyur Potdar
  • 7,158
  • 6
  • 25
  • 40