lundi 18 novembre 2019

Create Loop in if / else statement

I am trying to loop this function in the case the 'else' is reached but I'm having difficulties.

I tried while False and it doesn't do the print statements, I guess it kicks out of the function as soon as it ends up being false. I tried the True and I think that's the way to go but when it hits Else it just repeats. I'm thinking... maybe I need to do another Elif for the repeat of the whole function and the else as just an escape if needed.

def login(answer):
    while False:
        if answer.lower() == "a":
            print("You selected to Login")
            print("What is your username? ")
            break
        elif answer.lower() == "b":
            print("You selected to create an account")
            print("Let's create an account.")
            break
        else:
            print("I don't understand your selection")

Aucun commentaire:

Enregistrer un commentaire