Rock-Paper-Scissor Project


#1



When I run the code in bash, it asks for Select R for Rock, P for Paper or S for scissors but when I select one of the options nothing happens, no error just back to the bash script


no errors


it should have told me if i won, drew or lost against the computer


"""this is a rock paper scissors game"""
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)]
play_RPS()


#3

At the end of your play_RPS() function, call the decide_winner() function. At the minute you've only defined it, you aren't actually calling it to run it.


#4

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