Chapter 0.2 - Some nests hides many IFs in Python


Once you are feeling comfortable with the if, elif, and else statements, you can move on to nested conditional statements. We can use nested if statements for situations where we want to check for a secondary condition if the first condition executes as true. For this, we can have an if-else statement inside of another if-else statement. Let’s look at an example:


grade=int(input("Give me the grade: "))
if grade >= 65:
    print("Passing grade of:")

    if grade >= 90:
        print("A")

    elif grade >=80:
        print("B")

    elif grade >=70:
        print("C")

    elif grade >= 65:
        print("D")

else:
    print("Failing grade")

Don't forget the indentation!