简体   繁体   中英

python - loop break wont work second time

def play_again():
    again = input("would you like to play another game? ").lower()
    while play_again:
        if again == "yes":
            play_again()
        elif again == "no":
            print("thank you for playing with us")
            break
        else:
            again = input("only yes, or no answers are allowed: ").lower()
            continue

play_again()

If I run the code and input no, code exits.

If I run the code and input yes , code continues, but if second input is no , code won't exit:(

can someone help me?

thanks to those who replied, i removed the while loop and chose a diffrent way that now works:

    def play_again():
    again = input("would you like to play another game? ").lower()
    if again == "yes":
        play_again()
    elif again == "no":
        print("thank you for playing with us")
    else:
        print("only yes, or no answers are allowed")
        play_again()


play_again()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM