Python Forum

Full Version: Odd behavior with Rock Paper Scissor game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am following a tutorial for a rock paper scissor game and I made some changes to it to stray from the tutorial. Everything works except for the fact that sometimes the random choice doesn't appear to pick a choice and the score is not tabulated.

Here's the code I have, please help me identify what is going wrong:

import random
import sys

print("Rock, Paper, Scissors")

wins = 0
losses = 0
ties = 0

while True:
    print('%s Wins, %s Losses, %s Ties' % (wins, losses, ties))
    while True:
        playermove = input(
            "Enter your move: r(ock), (p)aper, (s)cissors or q(uit): ")
        if playermove == "q":
            print("Thanks for playing!")
            sys.exit()
        if playermove == "r" or playermove == "p" or playermove == "s":
            break
        else:
          print("Please type a valid character.")

    if playermove == "r":
      print("Rock versus...")
    if playermove == "S":
      print("Scissors versus...")
    if playermove == "p":
      print("Paper versus...")

    choices = ("r", "s", "P")
    compmove = random.choice(choices)

    if compmove == "r":
      print("Rock")
    elif compmove == "s":
      print("Scissors")
    elif compmove == "p":
      print("Paper")

    if playermove == compmove:
      print("It is a tie!")
      ties += 1
    elif playermove == "r" and compmove == "s":
      print("You win!")
      wins += 1
    elif playermove == 'p' and compmove == 'r':
      print('You win!')
      wins += 1
    elif playermove == 's' and compmove == 'p':
      print('You win!')
      wins += 1
    elif playermove == 'r' and compmove == 'p':
      print('You lose!')
      losses += 1
    elif playermove == 'p' and compmove == 's':
      print('You lose!')
      losses += 1
    elif playermove == 's' and compmove == 'r':
      print('You lose!')
      losses += 1 
Comparisons are case-sensitive. On lines 25 and 30, you've used capital letters, and everywhere else lower-case. That's going to cause problems. When the computer picks "P", none of the comparisons will match, and you don't have a else condition to catch that none of the other ones matched.
Thank you. Not sure how I missed that.