在井字语法错误而分配名称

问题描述 投票:0回答:1

所以我在写关于Python代码为井字游戏2名球员,并同时指定了球员名字的变量我得到了一个错误。我找不到错误。

import os
import time
import random

# Define the board
board = [" "," "," "," "," "," "," "," "," "," "]
#Define the print_board function
def print_board():
    print ("   |   |  ")
    print (" "+board[1]+" | "+board[2]+" | "+board[3]+" ")
    print ("   |   |  ")
    print ("---|---|---")
    print ("   |   |  ")
    print (" "+board[4]+" | "+board[5]+" | "+board[6]+" ")
    print ("   |   |  ")
    print ("---|---|---")
    print ("   |   |  ")
    print (" "+board[7]+" | "+board[8]+" | "+board[9]+" ")
    print ("   |   |  ")

os.system("clear")
print(a)
print_board()


n1=str(input("Enter Player 1 name")
n2=str(input("Enter Player 2 name")
b=str(input("Choose your symbol")

if b== "X" or "x":
    choice = input("Please select the place for your symbol X")
    board(choice) = "X"

我一直在N2变量得到错误说的语法是错误的。

任何帮助将是明显的。

python-3.x
1个回答
0
投票

尝试这个:

    n1=str(input("Enter Player 1 name"))
    n2=str(input("Enter Player 2 name"))
    b=str(input("Choose your symbol"))
© www.soinside.com 2019 - 2024. All rights reserved.