BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python Program to Check If number is Even or Odd

Last Updated: January 3, 2018 by Chaitanya Singh | Filed Under: Python Examples

In this post, we will write a Python program to check whether the number entered by user is even or odd.

Example: Check If number is even or odd

This program takes the input from user and checks whether the entered number is even or odd. We are receiving the value into a variable num and then we are dividing the num by 2 to see whether it is an even number or odd number.

num = int(input("Enter any number: "))
flag = num%2
if flag == 0:
    print(num, "is an even number")
elif flag == 1:
    print(num, "is an odd number")
else:
    print("Error, Invalid input")

Output:
Python check even or odd number

Related Posts:

  1. C Program to check if number is even or odd
  2. C++ Program to check whether input number is even or odd
  3. Java Program to check even or odd
  4. Python program to get user input
  5. Python Program to add two numbers

Top Related Articles:

  1. Python Program to Convert Celsius To Fahrenheit and Vice Versa
  2. Python Program to Convert Decimal to Hexadecimal
  3. Python Program to Check whether Year is a Leap Year or not
  4. Python Program to Check if a Number is Positive Negative or Zero
  5. Python Program to Find ASCII Value of a Character

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

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

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap