How do I correctly implement error reading in elif and if 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: grade > 65   ///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


You dont have to put info after else

If all of the above fail or dont match, print else statement


Do you think it could be a program bug? I removed the else. My code looks sound, I did not change the indentation at all from the default indentation


It’s not a bug, you just don’t put anything behind else:

So instead of:

else: grade > 65
        return "F"

you do:

        return "F"


You are basically checking twice if grade is more than 65 which is unnecesary.


I did that and still got indentation errror.


Try indenting again. Backspace till you get on the previous line and then press enter, it should indent the right way.

Or post your code so I can check


some of my greater than symbols (or also called crocodiles) were the wrong way


You fixed your error?


yes! :slight_smile: yes yes yes yes! I was looking at the greater than symbols and the internal logic did not make sense but you of course helped me by asking me to look at it again!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.