Python-if-else-statement .

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


IF-ELSE-Statement :

If-else statment is a extension of if-statement . It is allow to evaluate the specified condition if condition is true then the statement inside the if will be executed other wise control transfer to else part and the statement inside the else will be executed .

IF-Elese-statement-syntax :

if-else image


Example : Write a python program that check the age for voting .

age=15;
if(age>=18):
    print("Valid for vote")
else:
    print("Not valid for vote")
    
    OUTPUT : Not valid for vote
    


Example : Write a python program that check the even or odd number .

x=5
if(x%2==0):
    print("Even Number")
else:
    print("Odd Number")
    
    OUTPUT : Odd Number
    


Example : Write a python program check the userid and password for login .

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

Welcome to AndroidATPoint.

back image                     next image