0

I'm still pretty new at Python and am confused as to why my attempt counter is not increasing.

def start_game():
    print("\nWelcome to A Python Game")
    print("Choose one of the following:")
    print("1) Play game")
    print("2) About")
    print("3) Quit")
    firstchoice()

def firstchoice():
    max_attempts = 3
    attempts = 0
    while attempts < max_attempts:
        choice = input("> ")
        if choice == "1":
            game()
        elif choice == "2":
            gameabout()
        elif choice == "3":
            return None
        else:
            attempts =+ 1
            print("Invalid choice.")
            print("Attempts to successfully get past the main menu: ", attempts)

start_game()

If the user inputs anything but 1, 2 or 3, I want it to display "Invalid choice," followed by the number of attempts. However, while the variable does increase in the else condition, it immediately resets. Why is this? The program is not rerunning the function, right? It should be trapped in that while loop until some other condition is met. How can I make this work?

0 Answers0