Else If Statements - Python

Why do I get an error syntax? I’m not sure when and how “return” should be used.

https://www.codecademy.com/courses/learn-python-3/lessons/python-control-flow/exercises/else-if-statements

def grade_converter(gpa):
  grade = ""
  
  if gpa >= 4.0:
    return grade = "A"
  elif gpa >= 3.0:
    return grade = "B"
  elif gpa >= 2.0:
    return grade = "C"
  elif gpa >= 1.0:
    return grade = "D"
  elif gpa >= 0.0:
    return grade = "F"  

grade(2)

Not sure what this has to do with else if?

anyway, you can’t do return and assignment (=) on the same line. Why would you want this? You return the value, so the assignment is pointless.

1 Like