English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Fonctions en Python

Types de données en Python

Python file operations

Python objects and classes

Python date and time

Advanced Python knowledge

Python reference manual

Python program to check if a number is odd or even

Complete Python examples

In this example, you will learn to check if the number entered by the user is even or odd.

To understand this example, you should understand the followingPython programmingTopic:

Even if a number can be divided by2completely divisible, when the number is divided by2We will use the remainder operator % to calculate the remainder. If the remainder is not zero, the number is odd.

Source code

# Python program to check if the input number is odd or even.
# Even if a number is divisible by2The remainder is 0 as well.
# If the remainder is1,it is an odd number.
num = int(input("Enter a number: "))
if (num % 2) == 0:
   print("{0} is even".format(num))
else:
   print("{0} is odd".format(num))

Output1

Enter a number: 11
11 It is odd

Output2

Enter a number: 18
11 It is even

In this program, we ask the user to enter and check if the number is odd or even.

Complete Python examples