A number is even when it divides by 2 with nothing left over. The % operator gives that remainder.
The program
python
n = int(input("Enter a whole number: ")) if n % 2 == 0: print(f"{n} is even") else: print(f"{n} is odd")
Typed in this example: 7. Press Run to type your own.
output
Enter a whole number: 7 7 is odd
How it works
n % 2is the remainder whennis divided by 2. It is always 0 or 1.==compares two values. (A single=stores a value; it does not compare.)- This also works for negative numbers and zero:
-4 % 2is 0, so -4 is even, and so is 0.
Checking a list of numbers
python
for n in [3, 8, 0, -5]: print(n, "even" if n % 2 == 0 else "odd")
output
3 odd 8 even 0 even -5 odd
"even" if ... else "odd" is a conditional expression: a short form of if/else that gives back one of two values.