Rock, paper, scissors win and tie


#1

Hey everyone. I’s really appreciate some help with figuring out what’s wrong with my code. It seems to be running perfectly with no errors in the terminal. But when there’s a situation where the user should have won or tied with the computer it still says lost. Here’s my code:

""" This is a program that play rock, paper,scissors with the user"""

from random import randint
options = ["ROCK", "PAPER", "SCISSORS"]
message = {"tie":"It's a tie",
           "won":"Congrats! you won", 
           "lost": "Loser!"}
def decide_winner(user_choice, computer_choice):
  print "You selected %s" % user_choice
  print "The computers choice was %s" % computer_choice
  if user_choice == computer_choice:
    print message["tie"]
  elif user_choice == options[0] and computer_choice == options[2]:
    print message["won"]
  elif user_choice == options[1] and computer_choice == options[0]:
    print message["won"]
  elif user_choice == options[2] and computer_choice == options[1]:
    print message["won"]
  else:
    print message["lost"]
def play_RPS():
  user_choice = raw_input("Enter rock, paper or scissors: ")
  user_choice.upper()
  computer_choice = options[randint(0, 2)]
  decide_winner(user_choice, computer_choice)
play_RPS()

#2

this is the problem. You making it upper but you don’t save this anywhere. if you print user_choice after this line you will see that it is still in lower case. This is why it will always take the default path which is losing.

try this instead user_choice = user_choice.upper()

user_choice = raw_input("Enter rock, paper or scissors: ")  # input <-- rock
user_choice.upper()
print(user_choice)  # output --> rock

user_choice = raw_input("Enter rock, paper or scissors: ")  # input <-- rock
user_choice = user_choice.upper()
print(user_choice)  # output --> ROCK