07-A Nested IF ELSE example.py

Sign up Free. Don't forget to check out our challenges, lessons, solve and learn series and more ...

Code Snippet

#This is effectively an if statement within an if statement, note the indentation!

#Create an nested if statement in python that tells you the user's grade based on their score

score = input("Enter score: ")
score = int(score)
if score >= 80:
    grade = 'A'
    if score >= 70:
        grade = 'B'
        if score >= 55:
            grade = 'C'
            if score >= 50:
                grade = 'Pass'
                 grade = 'Fail'
print ("\n\nGrade is: " + grade)                    

Try it yourself