Get even odd program in python using function. In this tutorial, we will discuss the even and odd numbers by the program.
The program will give us the explanation of the even and odd numbers.
Odd numbers:-
If the input is divided by 2 and the remainder is other than 0 then it is called the odd number.
Even numbers:-
The number which divides by 2 the remainder is 0 then the number is called an even number.
It is called as even number if the given number is perfectly divisible by 2.
The remainder operator is divisible by % sign and the remainder is computed.
num=int (input (“Enter a number :”))
mod=num%2
if mod>0:
print(num, “is an odd number”)
else
print(num, “is an even number”)
Output:-
Enter a number: 11
11 is an odd number
Enter a number: 22
22 is an even number
1) Basically take the numbers from the users and then store it in the variable.
2) Then pass the number as an argument to the recursive function.
3) Define the base condition as a number less than 2.
4) Or call the function recursively with number-2.
5) Then the result is returned and checked if the number is odd or even.
6) Then print the final result.
7) Exit the program.