2

I am creating a Tic Tac Toe game for my homework in Python and I don't understand why it's giving me an Identification Error.

Here's my code:

import sys
import random

def draw(board, x, y):
    new_x = 0
    for line in xrange(y):
        for line2 in xrange(new_x, x):
            print "|", board[line2], "|",
        print
        new_x += y
        x += y

def player_team():
    choice = raw_input("Choose X or O... ")
    if choice.upper() == 'X':
        player = 'X'
        computer = 'O'
    elif choice.upper() == 'O':
        player = 'O'
        computer = 'X'
    else:
        player_team()
    return player, computer

if __name__ == '__main__':
    cord = 3
    board = [' * '] * cord**2
    draw(board, cord, cord)
    player, computer = player_team()

The actual text of the error is:

File "chess.py", line 29
  player, computer = player_team()
  ^
IndentationError: unexpected indent
chepner
  • 497,756
  • 71
  • 530
  • 681
Dimitar K. Nikolov
  • 130
  • 1
  • 2
  • 10
  • possible duplicate of [What to do with "Unexpected indent" in python?](http://stackoverflow.com/questions/1016814/what-to-do-with-unexpected-indent-in-python) – jb. Jun 06 '14 at 21:15

2 Answers2

9

You used a tabulation character instead of spaces in the last line of your code (it can be seen when editing your post). Juste replace it with four spaces and you won't get this error message any more!

julienc
  • 19,087
  • 17
  • 82
  • 82
3

You've mixed tabs and spaces. Don't do that; Python treats tabs like Notepad does, as enough spaces to reach the next 8-space indentation level.

To solve this, change all your tabs to sets of 4 spaces. It also helps to turn on "show whitespace" in your editor and run Python with the -tt flag (default in Python 3) so Python will tell you about ambiguous mixed tabs and spaces.

user2357112
  • 260,549
  • 28
  • 431
  • 505