Having syntax issues with the project rock, paper, and scissors


#1

I keep getting syntax error in the line:
elif user_choice_index == 0 and computer_choice_index == 2:

I am not sure what the issue is. I would be grateful if someone can point it out. I looked at other example and it seems to be correct.

""" This program is a game called Rock Paper Scissors. It is played between two users. The Scissor beats Paper and Paper beats Rock and Rock beats Scissors."""

from random import randint
from time import sleep 

options = ["R","P","S"]

MESSAGE_LOST = "You Lost!"
MESSAGE_WIN = "You Win!"

def decide_winner(user_choice,computer_choice):
    print "You selected: %s" % user_choice
    print "Computer selecting...."
    time.sleep(1)
    print "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 MESSAGE_WIN
      elif user_choice_index == 1 and computer_choice_index == 0:
        print MESSAGE_WIN
      elif user_choice_index == 2 and computer_choice_index == 1:
        print MESSAGE_WIN
      elif user_choice_index > 2:
        print "Invalid Option!"
        return
      else:
        print MESSAGE_LOST
                     
     
def play_RPS():
  print "Rock Paper Scissors"
  user_choice = raw_input("Select R for Rock, P for Paper,or S for Scissors: ")
  user_choice = user_choice.upper()  
  computer_choice = options[random.randiant(0,len(options)-1)]
  decide_winner(user_choice,computer_choice)
  
play_RS()

#2

That's the line at which the indentation is askewed. And all those the follow.


#3

I snuck by with,

if user_choice_index > computer_choice_index or user_choice_index == 0 and computer_choice_index == 2:
    print YOU_WIN
else:
    print YOU_LOST

Is it cheating?


#4

Off topic

I really like Sheldon's game because it uses a key ring approach which is mathematically sound.

Given a key, the two immediately adjacent are its conquerers, and the two opposite are the vanquished. Or the other way around, it really doesn't matter. What matters is an equal number of outcomes for or against. The primary concern is the odd number of objects in play. Even numbers are always unbalanced. Odd numbers are balanced once you take out the user choice. The other view is going around the key ring. 'against', 'for', 'against', 'for', 'mine'. No matter how we order the keys we get equal outcome possibilities.


#5

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