Python If else Statements

An else statement can be combined with an if statement. An else statement contains the block of code that executes if the conditional expression in the if statement is False or 0 .

  The else statement executes when the if statement is false.


Syntax of If..else block

if expression:
   statement(s)
else:
   statement(s)


# example of if..else 
x=10
if(x==9):
	print("value of x=9")
else:
	print("value of x is not 9")
value of x is not 9

Example : checking odd and even


# example of checking even and odd number
n=int(input("enter the  number "))

if(n%2==0):
	print("number is even")
else:
	print("number is odd")
enter the  number 3
number is odd

int()- It is used to convert string type value to int type value.

Example: checking leap year


#example of checking leap year
year=int(input("Enter the year "))
if(year%4==0):
	print("Year is leap")
else:
	print("year is not leap year")
Enter the year 2004
Year is leap