How to break a function to a specific spot after a failed test

def joe():
    while True:
        name = ""
        answer = ""
        print("What is your name? ")
        name = input()
        if name != "Joe":
            continue
        print("What is your password? (it is a fish) ")
        answer = input()
        if answer == "swordfish":
            break
    print("nice job, Joe")
    
     joe()

If I pass the frist statement and type in "Joe" i continue with the function, and all is good. but if I fail the second test, I break the function and get retrieved back to the "what is your name?" part of the function. How can I write a test that will upon failiure retreive me back to the "what is your password"? instead of the name test?


or try this:

def joe():    
    name = ""
    answer = ""
    print("What is your name? ")
    name = input()
    if name == "Joe":
        print("What is your password? (it is a fish) ")
        answer = input()
    if answer == "swordfish":
        return print("nice job, Joe")
    
    joe()

joe()

Try using the combination of a while True and `return statement my bro!

def joe():
    while True:
        print("What is your name? ")
        name = input()
        if name != "Joe":
            continue

        while True:
          print("What is your password? (it is a fish) ")
          answer = input()

          if answer == "swordfish":
            print("nice job, Joe")
            return
    
joe()

Add another while loop for the password part.

def joe():
    while True:
        print("What is your name? ")
        name = input()
        if name == "Joe":
            break
    while True:
        print("What is your password? (it is a fish) ")
        answer = input()
        if answer == "swordfish":
            break
    print("nice job, Joe")