Check ODD and EVEN
Table of Contents
In this tutorial, we will discuss the Python program to check whether a number is even or odd
In this post, we are going to learn how to check whether the given number is even or odd in Python language
Program 1
num=345
if(num%2)==0:
print("{0} is even".format(num))
else:
print("{0} is odd".format(num)) When the above code is executed, it produces the following result
345 is odd
In this program,
Program 2
num=int(input("Enter a number: "))
if(num%2)==0:
print("{0} is even".format(num))
else:
print("{0} is odd".format(num)) When the above code is executed, it produces the following result
case 1
Enter a number: 4567 4567 is odd
case 2
Enter a number: 486 486 is even
Approach
Program 3
#Python function to check Even or Odd
num=int(input("Enter a number: "))
def checkOddEven(num):
if (num%2==0):
print(num," is Even")
else:
print(num," is Odd")
checkOddEven(num) #call the function
When the above code is executed, it produces the following result
case 1
Enter a number: 179 179 is Odd
Case 2
Enter a number: 210 210 is Even
Approach
Program 4
#Code to check whether a number is even or odd -using recursion
def isEven(num):#function definition
if(num>2):
return (num%2==0)
return(isEven(num-2))
num=int(input("Enter a number to check odd or even: "))
#receive input from the user and stores variabe num
if(isEven(num)==True):
# number is passed as argument to the function
print(num," is an even")
else:
print(num," is an odd") When the above code is executed, it produces the following result
Case 1
Enter a number to check odd or even: 657 (657, ' is an odd')
Case 2
Enter a number to check odd or even: 7654 (7654, ' is an even')
Similar post
Python program to check whether a number is even or odd
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
Suggested post
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.