我的第一个其他条件跳到了第二个

时间:2017-07-31 11:56:05

标签: python python-3.x

所以我试图不让第一个ELSE继续进行,直到它满足要求输入只包含1或2或3的条件......但它很容易这样做......经过一次打印后它会去到第二个ELSE ......我在这里做错了什么?

def line_func(): # line to separate
print("==========================================================================") 

def vs1():
print("") # vertical space

def start1():
vs1()
print("=====================================================")
print("Would you like to start? Choose with (y)yes or (n)no.\n=====================================================\n")   
while True:
    start = input("Answer: ")
    vs1()
    if start == "y" or start == "Y" or start == "yes" or start == "YES" or start == "Yes":         
        line_func()
        vs1()

        menu1 = input("How would you like to proceed?\n\n1)Find an enemy to crush\n2)Restart game\n3)Exit game\n\nodgovor: ")
        if menu1 == "1":
            vs1()
            start_round()
        elif menu1 == "2":
            vs1()
            print("================= RESTARTING GAME ===================")
            vs1()
            print("=====================================================")
            print("Would you like to start? Choose with (y)yes or (n)no.\n=====================================================\n")
            continue
            start1()             
        elif menu1 == "3":
            print("Ok see you next time... bye bye :)")       
            break
        else:
            print("You have to choose one of the options to proceed...")

    elif start == "n" or start == "N" or start == "no" or start == "NO" or start == "No":
        print("Ok see you next time... bye bye :)")       
        break
    else:
        print("You have to choose with yes or no...")

start1()

2 个答案:

答案 0 :(得分:0)

尝试以下代码,为我工作:

def line_func(): # line to separate
    print("==========================================================================") 

def vs1():
    print("") # vertical space

def start1():
    vs1()
    print("=====================================================")
    print("Would you like to start? Choose with (y)yes or (n)no.\n=====================================================\n")   
while not start:
    start = input("Answer: ")
    vs1()
    if start == "y" or start == "Y" or start == "yes" or start == "YES" or start == "Yes":
        start = True
        line_func()
        vs1()

        menu1 = input("How would you like to proceed?\n\n1)Find an enemy to crush\n2)Restart game\n3)Exit game\n\nodgovor: ")
        if menu1 == "1":
            vs1()
            start_round()
        elif menu1 == "2":
            vs1()
            print("================= RESTARTING GAME ===================")
            vs1()
            print("=====================================================")
            print("Would you like to start? Choose with (y)yes or (n)no.\n=====================================================\n")
            continue
            start1()             
        elif menu1 == "3":
            print("Ok see you next time... bye bye :)")       
            break
        else:
            print("You have to choose one of the options to proceed...")

    elif start == "n" or start == "N" or start == "no" or start == "NO" or start == "No":
        start = True
        print("Ok see you next time... bye bye :)")       
        break
    else:
        print("You have to choose with yes or no...")
        start = False

start1()

答案 1 :(得分:0)

while True:
     line_func()
    vs1()

    menu1 = input("How would you like to proceed?\n\n1)Find an enemy to crush\n2)Restart game\n3)Exit game\n\nodgovor: ")
    if menu1 == "1":
        vs1()
        start_round()
    elif menu1 == "2":
        vs1()
        print("================= RESTARTING GAME ===================")
        vs1()
        print("=====================================================")
        print("Would you like to start? Choose with (y)yes or (n)no.\n=====================================================\n")
        continue
        start1()             
    elif menu1 == "3":
        print("Ok see you next time... bye bye :)")       
        break
    else:
        print("You have to choose one of the options to proceed...")

您需要的是另一个while循环。休息条件取决于您的需求。