Skip to main content
 首页 » 编程设计

python之缩进错误 : unexpected indent之Python 2. 7

2025年05月04日8lovecherry

<分区>

我正在用 Python 为我的家庭作业创建一个井字游戏,但我不明白为什么它会给我一个识别错误。

这是我的代码:

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() 

错误的实际文本是:

File "chess.py", line 29 
  player, computer = player_team() 
  ^ 
IndentationError: unexpected indent