To find odd and even number, we will be using if and else condition. This if and else condition will be created inside a function that we can call after getting value from the keyboard.

We will start by creating a function call oddeven which includes if and else statement. This oddeven function will have one parameter called “num”.

def oddeven(num):
if num%2 == 0:
print("Even number")
else:
print("Odd Number")

To find odd or even number, we have to divide the number by 2. If the remainder is zero, number is even. If not then that number is odd. oddeven function include one parameter “num” which takes the value when the function is call.

The next step is to ask user to input the number from keyboard.

number = int(input("Please enter any number: "))

At last calling the function and passing the number got from keyboard to the parameter “num” defined in the oddeven function.

oddeven(number)

Now inside the oddeven function, if condition will check whether the result of division of num by 2 is 0 or not. If the result is 0 or zero , statement ” Even number” will be printed. If not then printing the statement ” Odd number”.

Output

Please enter any number: 5
Odd Number

Full Code

def oddeven(num):
if num%2 == 0:
print("Even number")
else:
print("Odd Number")
number = int(input("Please enter any number: "))
oddeven(number)

### Like this:

Like Loading...

*Related*