2017-11-20 12 views
-5

エラーは、関数からreturn rightは、したがって、エラーを動作しません後なぜこのelif文は構文エラーを返しますか?

File "Scantron.py", line 28 

    elif len(test_answers) != len(test_key): 
    ^
SyntaxError: invalid syntax 

コマンドが非ゼロの状態1

def grade_scantron(test_answers, test_key): 
    right = 0 
    for i in test_answers: 
     if test_answers[i] == test_key[i]: 
      right += 1 
     return right 
     elif len(test_answers) != len(test_key): 
      return -1 
+2

インデントライン27、 '場合はループ内right'返す' test_answers [i]を== test_key [i]の場合: ' –

+0

してくださいコードにコンテキストを追加すると、if文全体を追加する必要があります。それに応じてあなたの質問をフォーマットしてください – chgsilva

答えて

0

elif声明で終了しましたと言います。 あなたはあなたのコードを編集して、インデントする必要があなたのreturn rightif文の中:

def grade_scantron(test_answers, test_key): 
    right = 0 
    for i in test_answers: 
     if test_answers[i] == test_key[i]: 
      right += 1 
      return right     # change here 
     elif len(test_answers) != len(test_key): 
      return -1 
関連する問題