2016-05-15 90 views
-1
def main(): 
    create_board() 
    print_board() 


def create_board(): 
    for x in range(4): 
     board.append(["O"] * 4) 

def print_board(): 
    for row in board: 
     print(" ".join(row)) 

这是我的代码来生成一个战舰游戏板。现在我想要做的是为每个零分配一个值。例如。 '1,1'将等于左上角,'1,2'=左上角的第二等等。当被问及: 火('你想要投射的输入坐标?') 以及如果玩家输入例如 1,1 就会知道它的顶部发射离开如何赋值给二维数组中的某些东西?

非常感谢

回答

0
>>> x = [[1,2],[3,4]] 
>>> print(x) 
[[1, 2], [3, 4]] 

>>> x[1][1] = 5 
>>> print x 
[[1, 2], [3, 5]]