Python program to check odd or even using recursion
- Home
- Find elements
- Python program to check odd or even using recursion
- On
- By
- 0 Comment
- Categories: 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
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
If statement in Python