Rock, Paper Scissors


#1

Whats wrong?

from random import randint
from time import sleep

options = ["R", "P", "S"]
lost_msg = "You lost!"
win_msg = "You win!"

def decide_winner(user_choice, computer_choice):
  print "Your choice: %s" % user_choice
  print "Computer selecting..."
  sleep(1)
  print computer_choice
  user_choice_index = options(user_choice)
  computer_choice_index = options(computer_choice)
  
  if user_choice_index == computer_choice_index:
    print "Tie!"
  elif user_choice_index == 0 and computer_choice_index == 2:
    print win_msg
  elif user_choice_index == 1 and computer_choice_index == 0:
    print win_msg
  elif user_choice_index == 2 and computer_choice_index == 1:
    print win_msg
  elif user_choice_index > 2:
    print "Invalid option selected!"
    return
  else:
    print lost_msg
    
def play_RPS():
    print "ROCK-PAPER-SCISSORS!"
    user_choice = raw_input("Select R for Rock, P for Paper, or S for Scissors: ")
    sleep(1)
    user_choice = user_choice.upper()
    computer_choice = options[randint(0,len(options)-1)]
    decide_winner(user_choice, computer_choice)

play_RPS()

#2

What error is coming up?


#3

Please post a link to the exercise, and as asked above, any error messages. Thanks.


#4

Without knowing exactly what error is coming up, refer to steps 11 and 12 of the exercise. Use the hints, if necessary. That should at least set you on the right path.


#5


#6

now the error I'm getting is the following:


#7

This is the code after some corrections, thanks!

"""
Rock-Paper-Scissors!
The program will do the following:
Prompt the user to select either Rock, Paper, or Scissors
Instruct the computer to randomly select either Rock, Paper, or Scissors
Compare the user's choice and the computer's choice
Determine a winner (the user or the computer)
Inform the user who the winner is
"""
from random import randint
from time import sleep

options = ["R", "P", "S"]
lost_msg = "You lost!"
win_msg = "You win!"

def decide_winner(user_choice, computer_choice):
print "Your choice: %s" % user_choice
print "Computer selecting..."
sleep(1)
print computer_choice
user_choice_index = options.index(user_choice)
computer_choice_index = options.index(computer_choice)

if user_choice_index == computer_choice_index:
print "Tie!"
elif user_choice_index == 0 and computer_choice_index == 2:
print win_msg
elif user_choice_index == 1 and computer_choice_index == 0:
print win_msg
elif user_choice_index == 2 and computer_choice_index == 1:
print win_msg
elif user_choice_index > 2:
print "Invalid option selected!"
return
else:
print lost_msg

def play_RPS():
print "ROCK-PAPER-SCISSORS!"
user_choice = raw_input("Select R for Rock, P for Paper, or S for Scissors: ")
sleep(1)
user_choice = user_choice.upper()
computer_choice = options[randint(0,len(options)-1)]
decide_winner(user_choice, computer_choice)

play_RPS()