How to Check if a Number is Even or Odd in Python

84 views

How to Check if a Number is Even or Odd in Python

How to Check if a Number is Even or Odd in Python

I need to determine whether a number is even or odd. How can I check this in Python?

solveurit24@gmail.com Changed status to publish February 16, 2025
0

In Python, you can determine if a number is even or odd by using the modulo operator %. If the remainder when dividing by 2 is 0, the number is even; otherwise, it’s odd.

Code Example:

num = 7
if num % 2 == 0:
    print(f"{num} is even.")
else:
    print(f"{num} is odd.")


This code checks the remainder when num is divided by 2. If the remainder is 0, it prints that the number is even; otherwise, it prints that the number is odd.

solveurit24@gmail.com Changed status to publish February 16, 2025
0