If else Statement & if-elif-else statement in python with program Examples
If else Statement & if-elif-else statement in python & its Program Examples with definitions:
if statement/condition:
Description:
The if statement is the simplest form. It takes a condition and evaluates to either True or False. If the condition is True, then the True block of code will be executed, and if the condition is False, then the block of code is skipped, and The controller moves to the next line.
Examples:
1)
a=10
b=20
if a<b:
print("yes a is less then b",'A=',a,'B=',b)
2)
a=input("please enter one number")
b=input("please enter two number")
if a==b:
print("yes a==b")
# print(a,b)
Description:
The if-else statement checks the condition and executes the if block of code when the condition is True, and if the condition is False, it will execute the else block of code.
Examples:
1)
a=input("Please enter your password to loing ")
if a=="Tom":
print("Your are login")
else:
print("you enter wrong password")
2)
a=input("enter your brother age")
b=input("enter your sister age")
if a>b:
print("your brother is elder ")
else:
print("your sister is younger ")
Chain multiple if statement in python/if-elif-else statement:
Description:
In Python, the if-elif-else condition statement has an elif blocks to chain multiple conditions one after another. This is useful when you need to check multiple conditions.
With the help of if-elif-else we can make a tricky decision. The elif statement checks multiple conditions one by one and if the condition fulfills, then executes that code.



Post a Comment