vendredi 11 janvier 2019

Nesting if/else statement in while loop

This is a text adventure game. The user is faced with the first scenario a(). If they choose 2, the game continues. If they choose 1, they die and are presented with the option to play again. Not sure what I'm doing wrong here.

"""
MAIN LOOP
"""
play_again = "yes"
while play_again == "yes" or play_again == "y":
    a()  # user makes a choice
    choice = choose_ans()
    check_ans_a(choice)  # intention: if user chooses "1", they die and are asked to play again
        if choice == "1":  # problem: Unexpected indent. If indent is deleted, b() becomes unreachable
            play_again = input('Play again?\n'
                               '(y)es ')
            break
        else:
            continue
    b()
    choice = choose_ans()
    check_ans_b(choice)

Aucun commentaire:

Enregistrer un commentaire