Finding ODD and Even number using Python

We will be using if … else condition statement to determine whether the number enter by user is odd or even.

Below is the logic to determine odd and even number

  • Use % modulus operator which provides remainder of the division
  • If number is divided by 2 and remainder is 0 then it is even number otherwise it is odd number.

Asking to enter any number.

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

Now checking whether division of number by 2 provides remainder 0 or not. If remainder is 0 then it is even number otherwise odd number.

if number%2 == 0:
    print('Number %s is Even'%number)
else:
    print('Number %s is Odd'%number)

OUTPUT

Please enter any number: 25
Number 25 is Odd

Running the same program and providing 66 value

Please enter any number: 66
Number 66 is Even

Complete Code

number = int(input('Please enter any number: '))
if number%2 == 0:
    print('Number %s is Even'%number)
else:
    print('Number %s is Odd'%number)

Leave a Reply

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 )

Google photo

You are commenting using your Google 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