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 4
4 is an even number

PROGRAMS
author's image
Abhijeet Pal Author and Editor in Chief @djangocentral

Abhijeet is a full-stack software developer from India with a strong focus on backend and system design. He is driven by the need to create impactful solutions that add value to the internet in any way possible.

LinkedIn Twitter Github

Latest Articles

Latest from djangocentral

Django 4.1 adds async-compatible interface to QuerySet

The much-awaited pull request for an async-compatible interface to Queryset just got merged into the main branch of Django.Pull Request - https://github.com/django/django/pull/14843 The Django core team has been progressively adding async suppor…
Read more →

3 min read

Making Django Admin Jazzy With django-jazzmin

Django admin is undoubtedly one of the most useful apps of Django. Over the years there has been very little change in the admin app as far as the UX is concerned and it's not a bad thing at all. Django admin was designed to provide a simple and minimali…
Read more →

4 min read