IndentationError: Unexpected Indent

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

Hi there,

working on Python 2 Rock ,Paper, or Scissors exercise - python and I keep getting this indentation error. :
File “”, line 39
** decide_winner(user_choice,computer_choice)**
** ^**
IndentationError: unexpected indent

I have looked through my code and I cannot see anything wrong. My understanding of the exercise is that you can have a function call within another function. In the case of this exercise, that is what I believe this is to happen because if I take the indentation out, it would be wrong (in my opinion fro a logic standpoint)

Kindly help me with this and where I went wrong.


It will be easier to evaluate the problem if you show your code. If you do so, be sure to use the </> icon in the menu bar at the top of the text box you are typing in to preserve your indentation and present readable Python code.

1 Like

Hi Patrick,

I did before and was advised to send the link instead. Here it is

This code will simulate Rock, Paper, Scissors game.
User selcts one option, the cumputer selects one option at random
We compare based on the rules of the game to determine the winner
from random import randint
options = ["ROCK","PAPER","SCISSORS"]
messages = {
  "tie": "Yawn it's a tie!",
  "won": "Yay you won!",
  "lost": "Aww you lost!"}

def decide_winner(user_choice,computer_choice):
  print "You selected %s " % user_choice 
  print "Computer selected %s " % computer_choice
  if user_choice == computer_choice:
    print messages["tie"]
  elif user_choice == options[0] and computer_choice == options[2]:
    print messages["won"]
    print options[0] + "smashes" + options[2]
  elif user_choice == options[1] and computer_choice[0]:
    print messages["won"]
    print options[1] + "coveres" + options[0]
  elif user_choice == options[2] and computer_choice == options[1]:
    print messages["won"]
    print options[2] + " cuts " + options[1]
    print messages["lost"]
def play_RPS():
  user_choice = raw_input("Enter Rock, Paper, or Scissors: ")
  user_choice = user_choice.upper()
  computer_choice = randint(options[0],options[2])


1 Like

The requested link was (probably) to the exercise, so that we could go there and take a look.
Anyway, I copied and pasted your code into the exercise and it worked fine, with only a small error having to do with the random computer choice.

Do the same, and you should do fine. The editor on these Python courses is a bit oversensitive to indentation errors. If you can’t see it, it usually suffices to out-dent the offending line to the left margin, then re-indent it in steps of two spaces at a time to the desired position.

1 Like

Thank from the explanation Patrick but am still not clear on the error you observed with the ransom computer choice. Please if you can break it down a bit I would appreciate.


1 Like

Run it. Does it work properly. What do you see?

1 Like

Thanks Patrick, am all good now.

I had to check each link indent and i also noticed the issues you pointed out on the use of the randint(low,high)