2016-07-02 14 views
-4

このコードを実行すると、次の行の:記号に構文エラーが表示されます==> if(total_size!=((len(fleet_grid)* len(fleet_grid [0 ]) - TOTAL_SIZE)):ifステートメントの末尾に構文エラーがあります

なぜそれがある

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 
+2

はい、あなたの括弧が一致しないためです。エラーはあなたにそれを伝えていませんでしたか? – stark

答えて

1

行方不明閉鎖は「)」私はあなたがipython に好ましくはプログラムを実行すると、あなたがそのような何かを書く場合の出力を読むことをお勧めします In [8]: File "your_file.py", line 13 if(some_variable: ^ SyntaxError: invalid syntax

0

可能性が不足して閉じますか ')'? あなたは

0

、あなたが2つ((LEN前に持って

if (total_size != ((len(fleet_grid)*len(fleet_grid[0])-total_size)): 

ここでは声明の中で括弧を開くの余分なペアが存在するためであろうと。

「(」が、の4「)」5持っています if(some_variable:

出力はになります:。。

関連する問題