Categories: If statementPython

Nested if statements in Python language

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

Syntax

Flow diagram

 

Flow diagram nested if

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
Example program

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
Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.