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

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 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.

And if the above condition doesn’t satisfy, it means that it is an odd number.

So in this way, we can check if the given number is even or odd.

Check out our other python programming examples

Leave a Reply

Your email address will not be published. Required fields are marked *