How do I correct the indentation error in a python switch clause?

here

def grade_converter(grade):
    if grade >= 90:
        return "A"
    elif grade >= 80 and grade > 90:
        return "B"
    elif grade >= 70 and grade > 80:
        return "C"
    elif grade >= 65 and grade > 70:
        return "D"
    else:    #indentation error is occurring here
        return "F"
      
# This should print an "A"      
print grade_converter(92)

# This should print a "C"
print grade_converter(70)

# This should print an "F"
print grade_converter(61)

I am learning error read and so learning good habits now will prevent me from asking dumb questions later. This is specifically a spacing error

I know my answers are correct because I got them right on previous exercises for code academy.

Please help ASAP as I am trying to launch my website and therefore am learning python ( I already have the front end sorted out)

First remove the comment thing. I think comments in python are # not // comment.

Then. The else never needs a condition. Just like in js or java or c++ etc.

1 Like

hold on for a second please. I made the changes. Error is still occuring

I had no errors in repl assuming you are using python 3? Check your indents.

1 Like

The else part is wrong.
The print syntax is wrong.
Your conditional logic is also wrong… (Read it aloud).

def grade_converter(grade):
    if grade >= 90:
        return "A"
    elif grade >= 80 and grade < 90:
        return "B"
    elif grade >= 70 and grade < 80:
        return "C"
    elif grade >= 65 and grade < 70:
        return "D"
    else:
        return "F"


# This should print an "A"
print(grade_converter(92))

# This should print a "C"
print( grade_converter(70))

# This should print an "F"
print(grade_converter(61))

I did it right after I asked you! Im so glad I figured it out on my own :slight_smile: I’m so glad I’m not making the same mistakes I did when I started! The crocodiles were in the wrong order.

# Complete the if and elif statements!
def grade_converter(grade):
    if grade >= 90:
        return "A"
    elif grade >= 80 and grade < 90:
        return "B"
    elif grade >= 70 and grade < 80:
        return "C"
    elif grade >= 65 and grade < 70:
        return "D"
    else:
        return "F"
      
# This should print an "A"      
print grade_converter(92)

# This should print a "C"
print grade_converter(70)

# This should print an "F"
print grade_converter(61)
      
# This should print an "A"      
print grade_converter(92)

# This should print a "C"
print grade_converter(70)

# This should print an "F"
print grade_converter(61)