IndentationError


#1



$ python RPS.py
File "RPS.py", line 16
print "Computer selecting..."
^
IndentationError: unindent does not match any outer i
ndentation level


I can't track down the indentation problem, any keener eyes able to help?


""" 
Rock, Paper, Scissors
Program
"""
from random import randint 
from sleep import time

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

lose = "You lost"

win = "You win"

def decide_winner(user_choice, computer_choice):
	print "user choice %s" % user_choice
  print "Computer selecting..."
  sleep(1)
  print "computer choice %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 "A tie"  
    elif user_choice_index == 0 and computer_choice_index == 2:
    	print win
    elif user_choice_index == 1 and computer_choice_index == 0:
        print win
    elif user_choice_index == 2 and computer_choice_index == 1:
        print win
    elif user_choice_index > 2:
        print "invalid choice"
    return  
    else:
        print lose
      
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()
  sleep(1)
  computer_choice = options[randint(0, len(options)-1)]
  
decide_winner(user_choice, computer_choice)
play_RPS()


#2

Since all the code is inside the function block, it should all line up with the same left margin. The if statement is good, but the lines above it are rather jagged.


#3

Thanks for that I corrected it and still get this error, any other observations?

File "RPS.py", line 22
if user_choice_index == computer_choice_index:
^
IndentationError: unindent does not match any outer i
ndentation level


#4

You're mixing tabs and spaces


#5

Holy smokes! Thanks team, I was indeed mixing tabs and spaces, lesson learned!


#6

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