Python Nested-if-else-statement .

In this session i have discussed nested if-else statement in Python .


NESTED-IF-ELSE-Statement :

Python allows the nesting of if-else statement means you can use the if-else with in if statement It is also decision making and branching statement .

If-Else-statement-syntax :

CSharp Nested if else image

Example : Write a python program that check the userid or password using nested if else statement .

uid = 10
pwd = 20
if (uid == 10):
    if (pwd == 20):print("Login successfull")
    else:print("Invalid password")
            
else:print("Invalid UserID")
    
    OUTPUT : Login successfull
    


Example : Write a python program that check the maximum number among three number using nested if-else statement .

x=20
y=10
z=50
if(x>y):
    if(x>z):
        print(x)
    else:
        print(z)
else:
    if(y>z):
        println(y)
    else:
        println(z)
                
    
    OUTPUT : 50
    


Welcome to AndroidATPoint.

back image                     next image