![]() |
How To Use IF Else Statement in Python |
How To Use IF Else Statement in Python
Syntax of if Statement
if (condition) :
statement
if (condition) :
statement
How To Use if Statement in Python?
age=int(input("Enter Your Age:"))
if(age>=18):
print("You can Drive Bike")
*****OUTPUT*****
Enter Your Age:21
You can Drive Bike
age=int(input("Enter Your Age:"))
if(age>=18):
print("You can Drive Bike")
*****OUTPUT*****
Enter Your Age:21
You can Drive Bike
When if the condition is the true body of if will execute otherwise the body of else execute.
Important Same Others If Else Statement
Syntax of if-else Statement
if (condition) :
Statement
else:
Statement
if (condition) :
Statement
else:
Statement
How To Use if-else Statement in Python?
age=int(input("Enter Your Age:"))
if(age>18):
print("You can Drive Bike")
else:
print("You can not Drive Bike")
*****OUTPUT*****
Enter Your Age:15
You can not Drive Bike
age=int(input("Enter Your Age:"))
if(age>18):
print("You can Drive Bike")
else:
print("You can not Drive Bike")
*****OUTPUT*****
Enter Your Age:15
You can not Drive Bike
When condition which is true first from the top will execute, otherwise else executed.
Syntax of if-else Statement
if (condition):
statement1
elif(condition):
statement2
elif(condition):
statement3
else:
statement4
if (condition):
statement1
elif(condition):
statement2
elif(condition):
statement3
else:
statement4
How To Use if-else-if Statement in Python?
age=int(input("Enter Your Age:"))
if(age<=15):
print("You are kid")
elif(age<=17):
print("You are no Young")
elif(age>=21):
print("You can Drive Bike")
else:
print("You can not Drive Bike")
*****OUTPUT*****
Enter Your Age:21
You can Drive Bike
age=int(input("Enter Your Age:"))
if(age<=15):
print("You are kid")
elif(age<=17):
print("You are no Young")
elif(age>=21):
print("You can Drive Bike")
else:
print("You can not Drive Bike")
*****OUTPUT*****
Enter Your Age:21
You can Drive Bike
Syntax of Nested if Statement
if (condition):
#statements
if(condition):
#statements
if(condition):
#statements
if (condition):
#statements
if(condition):
#statements
if(condition):
#statements
How To Use Nested if Statement in Python?
print("Enter one Number")
x=int(input())
print("Enter second Number")
y=int(input())
print("Enter third Number")
z=int(input())
if(x>y):
print("x number is grater:",x)
if(y>x):
if(y>z):
print("y number is grater:",y)
if(z>x):
if(z>y):
print("z number is grater:",z)
*****OUTPUT*****
Enter one Number
23
Enter the second Number
54
Enter the third Number
67
z number is greater: 67
print("Enter one Number")
x=int(input())
print("Enter second Number")
y=int(input())
print("Enter third Number")
z=int(input())
if(x>y):
print("x number is grater:",x)
if(y>x):
if(y>z):
print("y number is grater:",y)
if(z>x):
if(z>y):
print("z number is grater:",z)
*****OUTPUT*****
Enter one Number
23
Enter the second Number
54
Enter the third Number
67
z number is greater: 67