Python Program to Check if a Number is Odd or Even – 2022

Machine Learning Projects

Hey guys, in this blog we will see a Python Program to Check if a Number is Odd or Even.

Code

# Python Program to Check if a Number is Odd or Even

num = input('Enter the number -> ')

num = float(num)

if num%2==0:
    print(f'{num} is an even number')
else:
    print(f'{num} is an odd number')

Output

Enter the number -> 2
2.0 is an even number
Enter the number -> 3
3.0 is an odd number
Enter the number -> 8
8.0 is an odd number

Here we are simply using the mod operator (%) operator which finds the remainder after division.

So if num%2 == 0 it means, the number is fully divisible by 2 without any remainder. Hence it is an even number.

Check out our other python programming examples

Leave a Comment

Your email address will not be published.