Table of Contents
Nested if statements in Python language
In this tutorial, we will discuss the Nested if statements in Python language.
“Nested if” can check a condition using if statements one after another if the condition resolves to be true.
We can have one if … elif… else statements inside another if …. else statement. This is known as nested if in python language
Syntex
Flow diagram
Programs
Program 1
Program – Nested if in python |
When we executed the above program, it produced the following result
your age and GPA both are enough
Explanation
In the above program, first, the program checks outer if condition
If it is False, goes to else part statements
If it is True, body of outer if statements are executed and control moves to inner if
At the same time, skips outer else part statements
then the program checks inner if
If it is false executes its elae part statements
If it is True executes inner if statements and skips inner else statements
Program 2
When we executed the above program, it produced the following result
Output 1
Enter a number..5
number is positive
Output 2
Enter a number..-5
number is negative
Output 3
Enter a number..0
number is zero
Explanation
In the above program, when the given number is positive
printed “number is positive”
when the given number is Negative
printed “number is negative”
when the given number equal to zero
printed “number is zero”
Related post