How do I correctly implement error reading in elif and if statements?


#1

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: 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


#2

You dont have to put info after else

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


#3

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


#4

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

So instead of:

else: grade > 65
        return "F"

you do:

else:
        return "F"

#5

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


#6

I did that and still got indentation errror.


#7

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


#8

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


#9

You fixed your error?


#10

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!


#11

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