0

I'm building this rock, paper, scissors game and I've gotten quite far. However, I can't get the final scores to print correctly. No matter the situation, I always get 0 value on total rounds, total wins and ties.

I've been trying to add to these variables within the loop, however, I just cannot seem to figure this out.


import random

# a rock, paper, scissors game

loop = True

while loop is True:
    win = 0
    tie = 0
    lose = 0
    rounds = 0 

    usrchoice = input("Rock, Paper or Scissors? (Quit ends): ") # user makes a choice

    if usrchoice.title() == "Rock":
        pass

    ...

        if computer_choice == "Scissors":
            print("You WIN!")
            win = win + 1
            rounds = rounds + 1


        elif computer_choice == "Rock":
            print("It's a tie!")
            tie = tie + 1
            rounds = rounds + 1


        else:
            print("You LOSE!")
            lose = lose + 1
            rounds = rounds + 1




I expect the output to be anything, depending on the user of course, and not just 0. Like this:

>>> You played 0, and won 0 rounds, playing tie in 0 rounds.
1
  • rounds = 0, wins = 0 and ties = 0, you are setting 0 inside while loop so whatever you add into it, it sets to 0, remove those lines from while loop and place before the loop Commented Apr 3, 2019 at 4:40

3 Answers 3

1

You are setting your variables to 0 at the beginning of every loop. Move the variables above the loop to solve this problem.

Eg:


import random

# a rock, paper, scissors game
# foot beats cockroach, cockroach beats nuke and nuke beats foot

win = 0
tie = 0
lose = 0
rounds = 0 

loop = True

while loop is True:
    usrchoice = input("Foot, Nuke or Cockroach? (Quit ends): ") # user makes a choice

Sign up to request clarification or add additional context in comments.

Comments

0

Just declare them before the loop:

win = 0
loses = 0 
ties = 0
rounds = 0
while True:
    ...

What you are doing is every time the loop starts over again all the variables are set to 0 again. By declaring them before the loop the code will run through and only change the value for them when you increment the by 1 later in the loop.

Comments

0

You should initialize your variables outside the while not inside.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.