← Go Back

How to Determine if a Number Is Even or Odd

Using the remainder operator (%). For any integer n, if n % 2 returns zero, n is even; if it returns one, it is odd.

>>> a = 10
>>> b = 11
>>> a % 2
0
>>> b % 2
1

The following console program requests an integer and indicates whether it is even or odd:

n = int(input("Enter a number: "))

if n % 2 == 0:
print(n, "is even.")
else:
print(n, "is odd.")


integers arithmetic-operations remainder-operator


🐍 You might also find interesting: