Find elements

Python program to check odd or even using recursion

Python program to check odd or even using recursion

In this tutorial, we will discuss a concept of the  Python program to check odd or even using recursion

In this article, we are going to learn  how to  check  odd and even numbers using recursion in the

Python programming language

Check odd or even using recursion

What is an even or odd number?

When any integer ends in 0,2,4,6,8 and it can be divided by two with the remainder of zero, it is called as an even number.

Example of even numbers – 34,-64,78,788

When any integer ends in 0,1,3,5,7,9 and it cannot be divided without a remainder, it is called as an odd number.

Example for odd numbers – 33,-69,75,785

 

Here, We can use Python operators to find odd or even number in given numbers

Python program to check odd or even using recursion

Program 1

This program allows the user to enter a number and is used to check whether the given number is odd or even using recursion

def isEven(num):
     if(num<2):
         return (num%2 == 0)
     return (isEven(num-2))
num=int(input("Enter the number for check odd or even: "))
#received input from the user and stored variable nnm
if(isEven(num)==True):
#pass the number as an argument to the recursive function
    print(num,"is an even number")
else:
    print(num,"is an odd number")

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

Case 1

Enter the number for check odd or even: 235
(235, 'is an odd number')

 

Case 2

Enter the number for check odd or even: 346
(346, 'is an even number')

 

Similar post

Python code to check whether a number is odd or even

Python program to check a number is even or odd using the function

Python program to display even and odd numbers without if

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

Separate odd and even numbers in a list to different two list

Python code to find odd and even numbers from a list

 

Suggested for you

Function in Python

Recursion in Python

If statement in Python

Operator in Python

 

 

C++ program to check odd or even using recursion
Calculate the average of odd and even numbers in C
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…

2 months 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