RPS.py unsupported operand type(s) for -: 'list' and 'int'


#1



it is successfully showing "Select R for Rock, P for Papaer, or S for Scissors:" but after i input something, it shows**"TypeError: unsupported operand type(s) for -: 'list' and 'int'**"


"""
This is a game for
paper-scissors-stone!
cody.h
"""
from random import randint
from time import sleep

options = ["R","P","S"]
msg = "You win!"

def decide_winner(user_choice,computer_choice):
  print "user's choice is %s" %user_choice
  print "Computer selecting..."
  sleep(1)
  print "computer's choice is %s" %computer_choice
  sleep(1)
  user_choice_index = options.index(user_choice)
  computer_choice_index = options.index(computer_choice)
  if user_choice_index == computer_choice_index:
    msg = "it's a tie!"
    print msg
  elif user_choice_index == 0 and computer_choice_index == 2:
    print msg
  elif user_choice_index == 1 and computer_choice_index == 0:
    print msg
  elif user_choice_index == 2 and computer_choice_index == 1:
    print msg
  elif user_choice_index > 2:
    msg = "invalid input!"
    print msg
    return
  else:
    msg = "you lost!"
    print msg

def play_RPS():
  print "It's a Rock, Paper, Scssiors Game!"
  user_choice = raw_input("Select R for Rock, P for Papaer, or S for Scissors: ")
  user_choice = user_choice.upper()
  computer_choice = options[randint(0,len(options -1))]
  decide_winner(user_choice,computer_choice)

play_RPS()


#2

The subtraction should be outside of the function call.

len(options) - 1

#3

thank you so much!! it works:))


#4

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