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
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.