mercredi 9 novembre 2016

Python - Program That Prints Grade Using Nested If-Else Statements

I'm trying to create a program that prompts users to enter their grade, and then compares that value, x, in a series of nested If-Else statements:

x = int(input("What is your grade?"))
def grade(x):

if x >= 90:
        return "A"
    else:
        if x >= 80:
            return "B"
        else:
            if x >= 70:
                return "C"
            else:
                if x >= 60:
                    return "D"
                else:
                    return "F"

print( "Grade:", grade(x))

When I try to run this program, I get an error message:

ParseError: bad input on line 4

What's wrong with:

if x >= 90:

?

So far I haven't been able to get the dialogue box to show up asking for the user to enter their grade because of this error.

Aucun commentaire:

Enregistrer un commentaire