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

Latest Articles

Latest from djangocentral

Capturing Query Parameters of request.get in Django

In Django, the request object contains a variety of information about the current HTTP request, including the query parameters. Query parameters are a way to pass additional information in the URL and are used to filter or sort data. The request object p…
Read more →

2 min read

Understanding related_name in Django Models

In Django, related_name is an attribute that can be used to specify the name of the reverse relation from the related model back to the model that defines the relation. It is used to specify the name of the attribute that will be used to access the relat…
Read more →

2 min read