Rock-Paper-Scissor Project


#1



When calling the fuction in the end it says one of the parameters is not defined. decide_winner(user_choice, computer_choice)
user_choice is not defined.


i am pretty sure it is defined


from random import randint
from time import sleep
options = ["R", "P", "S"]
when_lost = "You Lose!"
when_win = "You Win!"
def decide_winner(user_choice, computer_choice):
  print "Your Choice is: %s" % user_choice
  sleep(1)
  print "The Computers choice is: %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 "Its A Draw!"
  elif user_choice_index == 0 and comuter_choice_index == 2:
    print(when_win)
  elif user_choice_index == 1 and computer_choice_index == 0:
    print(when_win)
  elif user_choice_index == 2 and computer_choice_index == 1:
    print(when_win)
  elif user_choice_index > 2:
    print "Invalid Option! Try Again!"
  else:
       print(when_lost)
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

the indention of this line:

decide_winner(user_choice, computer_choice)

is off. play_RPS() should call decide_winner.

because the indention is off, decide_winner is called before user_choice and computer_choice are defined


#3

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