Rock, Paper, Scissors project. Unknown cause for error


#1





I;m not sure what;s causing it. It tells me the traceback error line location but when looking over my code again i still can't fathom it. Any help would be great, thanks.


"""This program will simulate a game of rock paper scissors"""
from random import randint
from time import sleep

options = ["R", "P", "S"]
loss = "You lost!"
win = "Congratulations, you win!"

def decide_winner(user_choice, computer_choice):
  print "You selected %s" % user_choice
  print "Computer selecting..."
  sleep(1)
  print "The computer selected %s" % computer_choice
  user_choice_index = options.index(user_choice)
  computer_choice_index = options.index(computer_choice)
  if user_choice_index == computer_choice_index:
    print"It's a tie!"
  elif user_choice_index == 0 and computer_choice_index == 2:
    print win
  elif user_choice_index == 1 and computer_choice_index == 0:
    print win
  elif user_choice_index == 2 and computer_choice_index == 1:
    print win
  elif user_choice_index > 2:
    print"Invalid selection"
    return
  else:
    print loss
    

    
def play_RPS():
  print"Rock, Paper, or 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

here:

user_choice = user_choice.upper

calling a method has the following syntax:

methodName()

the parentheses are missing in your code, so you store the method in user_choice

then index() throws an error because the upper method is not in list


#3

Thank you worked a treat :smile:


#4

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