Syntax error and no starting if?

Can anyone tell me why I would be getting a snytax error on line 2 with the following code? I wrote the “def grad_coverter(gpa):” function and hit enter and checked it several times…

def grade_converter(gpa):
  elif gpa >= 4.0:
    return grade = "A"
  elif(gpa>=3.0):
    return grade = "B"
  elif(gpa>=2):
    return grade = "C"
  elif(gpa>=1):
    return grade = "D"
  elif(gpa>=0):
    return grade = "F"
  return grade

The first in the chain must be if ; only after if can you start with the elifs.

2 Likes
  File "main.py", line 20
    return grade = "A"
                 ^
SyntaxError: invalid syntax

The error message is hinting that assignments are not proper syntax in return statements.

return %value%

where %value% can be any expression.

1 Like