# Mistake Made - How do I fix this

Hi,

I have one more question. I was trying to create a rock, paper scissors game with python. Below is the code that I created. I must have made one or two mistakes (probably in the ComputerMove section) as it’s not working correctly.
Can you please help me and let me know how I can fix this and most importantly what I did wrong?

Thank you very much!

Respectfully,
Josh

import random, sys

print(‘Rock, Paper, Scissors’)

#These variables keep track of the number of wins, losses, and ties.
wins = 0
losses = 0
ties = 0

while True: # The main game loop.
print(’%s Wins, %s Losses, %s Ties’ % (wins, losses, ties))
while True:
print(‘Enter your move: ®ock §aper (s)cissors or (q)uit’)
PlayerMove = input()
if PlayerMove == ‘q’:
sys.exit()
if PlayerMove == ‘r’ or PlayerMove == ‘p’ or PlayerMove == ‘s’:
break
print(‘Type one of r, p, s, or q.’)

#Display what the player chose:
if PlayerMove == ‘r’:
print(“Rock vs…”)
elif PlayerMove == ‘p’:
print(“Paper vs…”)
elif PlayerMove == ‘s’:
print(“Paper vs…”)

#Display what the computer chose:
ComputerMove = random.randint(1,3)
if ComputerMove == 1:
ComputerMove == ‘r’
print(“Rock”)
elif ComputerMove == 2:
ComputerMove == ‘p’
print(“Paper”)
elif ComputerMove == 3:
ComputerMove == ‘s’
(“Scissors”)

if PlayerMove == ComputerMove:
print(“it’s a tie!”)
ties = ties + 1
elif PlayerMove == ‘r’ or ComputerMove == ‘s’:
print(‘You win!’)
wins = wins + 1
elif PlayerMove == ‘p’ and ComputerMove == ‘r’:
print(‘You win!’)
wins = wins + 1
elif PlayerMove == ‘s’ and ComputerMove == ‘p’:
print(‘You win!’)
wins = wins + 1
elif PlayerMove == ‘r’ and ComputerMove == ‘p’:
print(‘You lose’)
losses = losses + 1
elif PlayerMove == ‘p’ and ComputerMove == ‘s’:
print(‘You lose’)
loses = losses + 1
elif PlayerMove == ‘s’ and ComputerMove == ‘r’:
print(‘You lose’)
loses = losses + 1

Hi Josh,

Try to use three backquotes before and after the code you paste. This will keep the indentation, making it easier to read for people trying to help, and it avoids the automatic transformation of some of your characters like ® or §.

Also, it would be helpful to know the specific error message you are getting, or what happens vs what you were expecting to happen.

1 Like

Hey there Josh
It is hard to tell for certain what problems there are since we can’t see your indentation, could you please post your code formatted using this button

I can point out that you used an `or` instead of an `and` on line 44, I don’t believe you meant to do this.

You also seem to have used `loses` and `losses` for the same variable:

And final thing I saw was that you use the comparison operator ( == ) instead of the assignment operator ( = ) on lines 32, 34, 38:

Which won’t work because ( = ) says that a variable is equal to something:

``````a = 5 #a is equal to five
``````

Where as the comparison operator ( == ) checks to see if two things are equal:

``````if a == 5: #checks to see if a is equal to five
``````

Hopefully this is helpful

1 Like

Hi 8-bitgaming,

Thank you, you solved it, it works now!

It was probably a combination of == vs = and the losses vs loses.
Thank you very much for your clear explanations!

Josh

1 Like

Hi,

One quick follow up.
The two While loops; can you say what each one is checking?

while True: # What is this one checking and what happens if it’s False
print(’%s Wins, %s Losses, %s Ties’ % (wins, losses, ties))
while True: #What is this one checking and what happens if it is False?
print(‘Enter your move: ®ock §aper (s)cissors or (q)uit’)
PlayerMove = input()
if PlayerMove == ‘q’:
sys.exit()
if PlayerMove == ‘r’ or PlayerMove == ‘p’ or PlayerMove == ‘s’:
break
print(‘Type one of r, p, s, or q.’)

Thank you very much,
Josh

They are both checking if `True` is `True`.
since this obviously is `True` it is simply in infinite loop for your code.

I can’t say for sure since your code is not formatted so I can’t see indentation, but I would guess if the first one is `False` than the code will not run at all, and if the second one is `False` than it will run the first loop, which includes the `print` statement on line 2, check if the next loop should run, since it can’t it will skip it, and then run the first loop again.

You could test this by changing the values to `False`. Note that if you create an infinite loop you may have to refresh the page if you are online, or completely close the program on your computer, so make sure to save anything that needs to be saved first.

1 Like