How to Nest If Statements in Python


In this example we will show how to nest if statements in if statements in Python.

Source Code

num = int(input('Type a number between 0 and 100: '))
if num > 50:
    print("The number you entered is above 50,")
    if num > 75:
        print("and also above 75!")
    else:
        print("but not above 75.")

Output:

Type a number between 0 and 100: 80
The number you entered is above 50,
and also above 75!
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments