Program to check whether number is odd or even using function

This blog uses a function to find odd and even number

First create a function that finds odd and even number. In below code. function name is oddeven() with single parameter. Logic is simple. If number returns 0 when divided by 2, it is even number otherwise odd number

def oddeven(num):
    if num%2==0:
        print('Number %d is Even'%num)
    else:
        print('Number %d is Odd'%num)

Asking user to input the number

number = int(input('Enter number : '))

Calling the function and passing value received from user

oddeven(number)

Output

Enter number : 7
Number 7 is Odd
Enter number : 10
Number 10 is Even

Complete Code

def oddeven(num):
    if num%2==0:
        print('Number %d is Even'%num)
    else:
        print('Number %d is Odd'%num)

number = int(input('Enter number : '))
oddeven(number)
Advertisement

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s