[英]How can I create a matrix in which the user inputs both rows and columns and then enters the values for each position in Python?
[英]How can I create a function with two parameters which both can have multiple inputs or data?
我正在创建一个井字游戏。 我有一个功能,可以替换用户选择的电路板部分,然后计算机就会发挥作用。 该函数设置为插入两个参数(user_choices 和 computer_choices)。 但是,在第一轮之后,我需要该函数能够在 user_choices 和 computer_choices 中进行多项选择。
我认为使用列表可以解决这个问题,但我猜参数不能将列表作为数据。
我对编码很陌生,所以我可能会遗漏一些非常明显的东西。 有什么想法吗?
def making_new_board(user_choices, computer_choices):
new_board = ""
for character in board:
if character == user_choices:
new_board += user_symbol
elif character == computer_choices:
new_board += computer_symbol
else:
new_board += character
time.sleep(1)
print(new_board)
我建议您使用 3x3 网格,而不是这样做
board = []
for i in range(3):
board.append([""], [""], [""]) # This will create a board of 3 by 3
您可以使用打印此
for i in board:
print(i)
要编辑董事会中的特定peice,您可以使用它
board[y][x] = "O"
注意:Y 值是从上到下而不是从下到上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.