else和elif语句导致if语句

时间:2018-01-19 08:14:12

标签: python if-statement

你好我是python编码的新手,我想知道为什么输入它会产生if语句。

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()

1 个答案:

答案 0 :(得分:0)

试试这个:

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()