Support Our Site

To ensure we can continue delivering content and maintaining a free platform for all users, we kindly request that you disable your adblocker. Your contribution greatly supports our site's growth and development.

Python Program to Check If number is Even or Odd

1 min read

Problem Definition

Make a Python program to check wheater the given number is Even or Odd.

Solution

If a number is exactly divisible by 2 then it is an even number else it is an odd number. In this article, we will use this particular logic to create a Python program to find whether the number given by the user is Even or Odd.

Algorithm

  1. Take input from the user and store it in a variable
  2. Divide the number by 2
  3. Print the final result
  4. End

To understand the program you need to have an understanding of following Python concepts.

Program

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

Runtime Test Cases

Enter a number 44 is an even number


PROGRAMS

Latest Articles

Latest from djangocentral

How to Use Subquery() in Django With Practical Examples

In the realm of web development, Django stands as a powerful and versatile framework for building robust applications. One of the key aspects of developing efficient and optimized web applications is handling database queries effectively. In this article…
Read more →

4 min read

DRF Serializer: Handling OrderedDict and Converting It to a Dictionary or JSON

In Django Rest Framework (DRF) tests, when you access serializer.data, you might encounter an OrderedDict instead of a regular dictionary. This behavior is intentional and reflects the design of DRF's serialization process.Understanding the Problem The u…
Read more →

3 min read

Django Rest Framework CheetSheet: Mastering API Development

Django Rest Framework (DRF) is a powerful toolkit that makes building robust and scalable web APIs with Django a breeze. Whether you're a seasoned Django developer or a newcomer, having a comprehensive cheat sheet at your disposal can be a game-changer. …
Read more →

5 min read

How to Perform NOT Queries in Django ORM

In Django, performing NOT queries allows you to exclude certain records from the query results based on specific conditions. The NOT operator, represented by the tilde (~) when used in conjunction with the Django ORM's Q object, helps you construct compl…
Read more →

3 min read