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

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

1 day ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago