Check value

Python program to check whether a number is even or odd

Python program to check whether a number is even or odd

In this tutorial, we will discuss the Python program to check whether a number is even or odd.

In this program, we are going to learn about how to find  odd or even number from given number using if else statements in Python programming language

 

What is Even or Odd

When the number is divided by 2 and the balance becomes zero. the above number is called as the even number – eg 2,4,6,8,10

and on the other sides when it is divided by 2 and balance becomes 1 there are called odd numbers or uneven numbers

 

Using modular operator

Program 1

Once This program received the number it will check the given number either odd or even.

After the program received input from the user, it is stored in the variable of num. then program divides the value of num into 2 and displays the output

#Python program to ceck if the input number is even or odd
num=int(input("Enter a number for check odd or even: "))
if(num%2)==0:
    print(num," Is even")
else:
    print(num," is odd")

When the above code is executed, it produces the following results

Case 1

Enter a number for check odd or even: 34
34 Is even

Case 2

Enter a number for check odd or even: 59
59 is odd

when we use the modular operator, if it is the remainder appears as 0, it is called even number and if the remainder displays the balance as one, it is called as odd or uneven number

 

Using Bitwise operator

Program 2

#check even or odd of a given  number by the user
num=int(input("Enter a number for the check even or odd:  "));
if(num&1==1):
    print(num, "is a odd number");
else:
    print(num, "is a even number");

When the above code is executed, it produces the following results

Case 1

Enter a number for the check even or odd:  59
59 is a odd number

Case 2

Enter a number for the check even or odd:  66
66 is a even number

Using Divisional operators

Program 3

#check even or odd of a given  number by the user
#check even or odd without using modular and bitwise operator
num=int(input("Enter a number for check even or odd:  "));
number=(num/2)*2
if(number==num):
    print(num, "is a even number");
else:
    print(num, "is a odd number");

When the above code is executed, it produces the following results

Case 1

Enter a number for the check even or odd:  99
99 is a odd number

Case 2

Enter a number for the check even or odd:  20
20 is a even number

 

Same program in other language

Java program to check whether a number is even or odd

C++ program to check whether a number is even or odd

C program to check whether a number is even or odd

 

Similar post in Python

Python program to check whether a number odd or even

Python program to check a number odd or even using function

Python program to display even and odd number in the given range

Python code to display all even and odd numbers from 1 to n

Python code to display all even and odd numbers without if

 

 

 

Cpp program to check whether a number is even or odd
Find Factorial:Python program to using function
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago