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

So implementing what stetim 94 set your code should look like this:

def grade_converter(gpa):
  grade = ""

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

grade_converter(2)

But consider that you are giving as an input an integer and your function is comparing to a float. idk if it will work on that end.