Check Even or Odd in Python
num % 2. Remainder 0 means even. That is the whole trick.
BeginnerBasic Python ProgramsExample 5 of 25
check-even-or-odd.py
1# Program to check if a number is even or odd23num = int(input("Enter an integer: "))45if num % 2 == 0:6 print(num, "is even")7else:8 print(num, "is odd")
Output
Enter an integer: 7 7 is odd
In this one
- n % 2 == 0 means even
- don't hide that behind a bare if n % 2
What's going on
Even means divisible by 2. % gives the remainder.
7 % 2 is 1 → odd. 8 % 2 is 0 → even.
Negative numbers: -3 % 2 is 1 in Python, so this still calls it odd. Don't overthink it for now.
People write if num % 2: and skip == 0. That works (1 is truthy) and is harder to read. Keep the == 0.
After this program
If the idea is still fuzzy, read Day 1: Introduction to Python in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 25 basic python programs, or see every topic on Python exercises.