Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Nested if statements in Python language

Posted on October 3, 2017January 24, 2020

Table of Contents

  • Nested if statements in Python language
    • Syntex
    • Flow diagram
    • Programs
    • Related

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

Nested if statements
Syntax

Flow diagram

 

Nested if statements in Python language
Flow diagram nested if

Programs

Program 1

Nested if in Python language - Example program
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
Nested if statements
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
While Loop in Java      while Loop in C++     While Loop In C

Do-while Loop in Java    Do-while Loop C++      Do-while loop in C 

For Loop in C++       For Loop in C         For loop in java

If condition C++       If condition in Java   If condition in C
If elif statement Python

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes