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


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
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..."
  print "computer's 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:
    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
    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))]



The subtraction should be outside of the function call.

len(options) - 1


thank you so much!! it works:))


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