/* */ Click to Join Live Class with Shankar sir Call 9798158723

Python if elif else Statement


Python support if elif else statements to test additional conditions apart from the initial test expression the if elif else construct works in the same way as a usual if else statement if elif else construct is also known as nested if construct

Syntex of python if elif else statement

if:condition:

    statement 1
    statement 2
    statement..n

elif condition:

    statement 1
    statement 2
     elif condition:

    statement 1
    statement 2
    statement..n

else:

    statement 1
    statement 2
    


The block of statement ( after : colon ) is executed if condition is TRUE else statement will be executed

Note: "in elif statement else part is not conpulsory"

Q.) program to test whether a number entered by the user is negative positive or equals to zero.
n=int(input("Enter first Number"))
if (n==0):
    print("number is equal to zero")
elif(n>0):
    print("number is positive")
else:
    print("the number is negative")
      
 
Output
enter a number:0

number is equal to zero