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

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

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes