【发布时间】:2016-07-20 05:03:53
【问题描述】:
以下 Python 代码:
def CheckIfSunk(Board):
Row, Column = GetRowColumn()
if Board[Row][Column] == "A":
Ships = "Aircraft Carrier"
elif Board[Row][Column] == "B":
Ships = "Battleship"
elif Board[Row][Column] == "S":
Ships = "Submarine"
elif Board[Row][Column] == "D":
Ships = "Destroyer"
elif Board[Row][Column] == "P":
Ships = "Patrol Boat"
elif Board[Row][Column] == "P":
Ships = "Patrol Boat"
elif Board[Row][Column] == "N":
Ships = "NEW"
Board[-1][Ships] -= 1
if Board[-1][Ships] == 0:
print Ships + " Sunk"
我收到此错误:
Board[-1][Ships] -= 1 TypeError: 字符串索引必须是整数,而不是 str
我该如何解决这个问题,非常感谢任何帮助
【问题讨论】:
标签: python string python-2.7 integer indices