Python program to check whether a number is even or odd
- Home
- Check value
- Python program to check whether a number is even or odd
- On
- By
- 0 Comment
- Categories: Check value, Find elements
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