The number of tries never increments by more than one in Python - help please?
Question: Whenever it takes me several tries to beat the game, it always says the
number_of_guesses is 1, which isn't true. What have I done wrong?

My code:

    
    
    import random
    
    print("Welcome to Rock, Paper, Scissors. \nYou will be going up against the computer, who will randomly",
      "choose an object to duel you with!")
    
    user_win = False
    
    while not user_win:
    
        user_guess = input("\nChoose either Rock, Paper or Scissors: ")
        user_guess = user_guess.lower()
    
        if user_guess != "rock" and user_guess != "paper" and user_guess != "scissors":
            print("You didn't enter a valid guess. Try again, please.")
            user_guess = input("\nChoose either Rock, Paper or Scissors: ")
            user_guess = user_guess.lower()
    
        computer_guess = random.randint(1,3)
    
        if computer_guess == 1:
            computer_guess = "rock"
        elif computer_guess == 2:
            computer_guess = "paper"
        else:
            computer_guess = "scissors"
    
        print("Your guess:", user_guess.capitalize(), "\nComputer guess:", computer_guess.capitalize())
    
        number_of_guesses = 1
    
        if user_guess == computer_guess:
            print("\nThe game is a tie. You guessed", user_guess, "and so did the computer.")
            number_of_guesses += 1
            user_win = False
        elif (user_guess == "rock" and computer_guess == "scissors") or (user_guess == "paper" and computer_guess == "rock"):
            print("\nCongratulations! You have beaten the computer by playing", user_guess.capitalize(), "while the computer played", computer_guess.capitalize())
            user_win = True
            number_of_guesses += 1
        else:
            print("\nDamn! The computer won by playing", computer_guess.capitalize(), "while you played", user_guess.capitalize())
            user_win = False
            number_of_guesses += 1
    
    if number_of_guesses == 1:
        print("\nYou won, and it only took you %d try!" % number_of_guesses)
    else:
        print("\nYou won, and it only took you %d tries!" % number_of_guesses)
    
    input("\nPress enter to exit the program.")
    

I think that's formatted correctly. It's not easy to put code in here. Thank
you!


Answer: First of all in the while loop you always initialize `number_of_guesses = 1`
on every run. That is why this will always be 1 in each run.

Take this initialization before the while.

