简体   繁体   English

二维列表函数,我不知道如何打印输入,python

[英]2d list functions, i cant figure out how to print input, python

my code is trying to set the point in the list they chose to an x, please assist in changing the code so that it works, here's the code:我的代码试图将他们选择的列表中的点设置为 x,请协助更改代码以使其正常工作,这是代码:

position = input("x or y: ")
board = [
    [" ", " ", " "],
    [" ", " ", " "],
    [" ", " ", " "],
    [" "]
    ]
gamewon = False
game_start = "Enter \"s\" when ready to start game";







def game1(placement1, placement2):
    placement1 = input("row: ")
    placement2 = input("column: ")
    board[placement1][placement2] = "x"
    print(board)
 #Assign values to the parameters.
 placement1 = None
 placement2 = None
 board = [
[" ", " ", " "],
[" ", " ", " "],
[" ", " ", " "],
[" "]
]

 def game1(placement1, placement2, board): #Add board as a parameter
        placement1 = int(input("row: "))
        placement2 = int(input("column: ")) 
        board[placement1][placement2] = "x" #Input has to be an integer for this to work
        print(board)

#Call the function
game1(placement1, placement2, board)

This will change the index in the nested list to an x after user Input这将在用户输入后将嵌套列表中的索引更改为 x

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM