Here in this article, we have provided a python source code that checks if the user entered number is an Even or Odd number.
Prerequisite topics to create this program.
Steps
- First, we ask the user to enter a number.
- Using the int() function we will convert the entered string into an integer value.
- Using the if....elif and Arithematic modules statement we check for conditions.
Python Program to Check if a Number is Odd or Even:
Code
number = int(input("Enter a Number: "))
if number %2==0:
print(number, "is an Even Number")
else:
print(number,"is an Odd Number")
Output 1:
Enter a Number: 13
13 is an Odd Number
Output 2:
Enter a Number: 100
100 is an Even Number
Conclusion
In this python tutorial, you learned how to check if a number is Odd or Even in python. We generally use the modules % operator to check if the number is completely divisible by 2 or not. If the number is completely divisible by 2, the % operator returns 0 else it returns a non 0 value.
People are also reading:
- Program to swap two numbers
- Program in C++ and python to convert temperature from Fahrenheit to Celsius and vice-versa
- C++ and Python Program to check whether the year is a leap year or not
- C++ Program Calculator to perform Arithmetic Operations using Switch Case
- C++ & Python Program to reverse a number
- C++ & Python Program to Insert an Element in an Array
- Program to convert a given number of days into years, weeks and days
- Program to check whether the entered number is prime or not
- Program to find the divisors of a positive Integer
Leave a Comment on this Post