Please help! The output always results in a loss no matter which option is chosen


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<In what way does your code behave incorrectly? Include ALL error messages.>
When running ‘python RPS.py’ no matter which option the user chooses it results in a loss.

<What do you expect to happen instead?>
I’m thinking it is an indentation problem but, I’m not sure.


from random import randint
options = ["ROCK", "PAPER", "SCISSORS"]
message = {
  "tie": "It'sa tie", 
  "won": "You won", 
  "lost": "You lost"}

def decide_winner(user_choice, computer_choice):
  print "You selected: %s" % user_choice
  print "The computer selected: %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():
  print "Rock, Paper, or Scissors?"
  user_choice = raw_input("Select R for Rock, P for Paper, or S for Scissors: ")
  user_choice = user_choice.upper()
  computer_choice = options[randint(0, 2)]
  decide_winner(user_choice, computer_choice)
play_RPS()

#2

Hi @joshua741852,

When you are promoted to make a choice, what do you type into the console?


#3

I type ‘s’ or ‘S’ for scissors, the same for the other options and I still the ‘you lose’ output.


#4

So after taking a break and looking at your question I ended up realizing that I needed to type out rock, paper, or scissors since i never declared the ‘s’ for scissors and so on, thank you!


#5

or r, p and s should be the options in your options list.


#6

That is one of your possibilities.

Also see @stetim94’s suggestion. That would make it easier to play the game because the user would only need to type in one letter to specify a choice.

Another possibility is to work it out so that the user could either enter the entire word, or part of it, such as only the first letter. You would do the following to guarantee that the choice would be converted to one uppercase letter …

  user_choice = user_choice[0].upper()

In that case, you would also modify the original assignment to options as described above.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.