Pycharm给出错误:
print(' '.join(board[row]).replace('*', ' '))
TypeError: 'int' object is not subscriptable
对于以下代码
print(' ', end='')
print(' '.join([str(row) for row in range(N)]))
print(' ', end='')
print(' '.join(['-' for _ in range(N)]))
for row in range(0, N, 1):
print(row, end=' | ')
if player == COMPUTER:
print(' '.join(board[row]).replace('*', ' '))
else:
print(' '.join(board[row]))
print()
我在这个函数中设置了board:
def GetValueFromUser(player):
board = []
for i in range (0,N):
board.append(([" "]*N))
for i in range(1, NUMBER_SHIP):
for ship_to_place in range(0, SHIP_SIZE_TO_COUNT[i]):
print("Your current board:")
print_board(board, player)
x = input("Enter location for Battleship of size {}:"
.format(i))
while 1:
x, y = x.split(",")
y, z = y.split(" ")
if check_location_and_place_ship(board, int(x), int(y), z,
i):
break
else:
print("ERROR: Invalid location")
x = input("Enter location for Battleship of size {} "
"again:"
.format(i))
return board
我搜索这个错误是什么,但越来越难解决它与列表理解在这种情况下 问题来源StackOverflow 地址:/questions/59382945/array-2d-is-not-subscriptable
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。