我正在爲學校製作一個棋盤遊戲,我希望能夠找到他們所在的地點編號的索引,並用他們的計數器(「x」或「y」)替換棋盤上的數字。如何在python中找到二維數組中的值?
board = [
["43","44","45","46","47","48","49"],
["42","41","40","39","38","37","36"],
["29","30","31","32","33","34","35"],
["28","27","26","25","24","23","22"],
["15","16","17","18","19","20","21"],
["14","13","12","11","10","9 ","8 "],
["1 ","2 ","3 ","4 ","5 ","6 ","7 "]
]
for line in board:
print (line)
roll = input("Player " + player + " press enter to roll the dice")
print ("Your counter is",counter)
if roll != "blablabla":
die1 = random.randint(1,6)
die2 = random.randint(1,6)
dice = die1 + die2
print (die1)
print (die2)
print ("You rolled",dice)
if player == "one":
place1 =(place1+dice)
print ("P1's place is",place1)
else:
place2 =(place2+dice)
print ("P2's place is",place2)
如何在板中找到字符串版本的「place1」或「place2」,並用其他內容替換該索引?
謝謝!
Python列表有一個'index(value)'方法 – Grimmy