【发布时间】:2016-07-02 23:01:46
【问题描述】:
当我运行此代码时,我在以下行中的 : 符号处收到语法错误 ==> if (total_size != ((len(fleet_grid)*len(fleet_grid[0])-total_size)):
这是为什么呢?
def validate_character_count(fleet_grid, ship_characters, ship_sizes):
"""(list of list of str, list of str, list of int) -> bool
Checks that the fleet on the grid matches the character and size description
"""
validity = True
total_size = 0
for size in ship_sizes:
total_size += int(size)
for row in fleet_grid:
for position in row:
if not (position.isnumeric() and position.isalpha()):
total_size += 1
if (total_size != ((len(fleet_grid)*len(fleet_grid[0])-total_size)):
validity = False
【问题讨论】:
-
是的,那是因为你的括号不匹配。错误没有告诉你吗?
标签: python syntax syntax-error