Write a python program to check whether a given number is even or odd.

 For checking a Given number is even or odd we have two way:-

Method 1:-
                    In this method we find the reminder of the number by 2 with the help of modulo operator (%) and if reminder is 0 then it is a even number otherwise it is a odd number.

n=int(input(“number=”))
if n%2==0:
print(“Even number”)
else:
print(“Odd number”)

output:-
number=5
Odd number


Method 2:-

                        In this method first we find the integer division of the by 2 and  multiply by 2 in to the result if we got the number then number is even otherwise number is odd number
Ex:-
        Take number is 5
        step 1:- find integer division by 2 i.e.  5//2=2
         step 2:-  again multiply by 2 in the result  i.e.   2*2=4 
         since 4 is not equal to the given number so it is a odd number
2)
      Take number is 6
        step 1:- find integer division by 2 i.e.  6//2=3
         step 2:-  multiply by 2 in the result  i.e.   3*2=6
         since 6 is  equal to the given number so it is a even number

n=int(input(“number=”))
int_div=n//2
mul=int_div*2
if mul==n:
print(“Even number”)
else:
print(“Odd number”)

 Output:-
number=6
Even number


One thought on “Write a python program to check whether a given number is even or odd.

Leave a Reply

Your email address will not be published.