OCJP

Nested If and ElIf in Python

In Python we can use Nested If (If within if) and Else if Ladder for Multiple Conditions. Following examples shows the syntax of if..elif

x=int(input("Enter X"))
y=int(input("Enter Y"))
z=int(input("Enter Z"))

if x>y:
    if x>z:
        print("X is Great")
    else:
        print("Z is Great")
else:
    if y>z:
        print("Y is Great")
    else:
        print("Z is Great")
        

#Another Way

if x>y and x>z:
    print("X is Greater")
elif(y>z):
    print("Y is Greater")
else:
    print("Z is Greater")

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?