Odd or Even in Python

 Python: Odd or Even 

In this blog, Let us see how we can write a program in Python to find whether a number is even or odd.

Code:


num=int(input("Enter a number:"))
if(num%2==0):
    print(f" {num} is an even Number")
else:
    print(f"{num} is odd Number")

Output:

Enter a number:53
53 is odd Number

Explanation:

  1. We are getting the number as input from the user and converting it into integer data type using the int() function and storing it in the num variable.
  2. Next, we are checking if num%2 == 0 if it is true then it is an even number otherwise it is an odd number.

Why we are using num%2== 0?

because we know that all even numbers are divisible by two, while odd numbers are not.

Post a Comment

Previous Post Next Post