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