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

Python basic tutorial

Python flow control

Python Functions

Python Data Types

Python file operations

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Python program to check if a number is odd or even

Python complete example

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 be2completely divisible, when the number is divisible 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 is1It is odd.
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 input and check if the number is odd or even.

Python complete example