Editor

Even or Odd

Beginner · Write the code · from Python If-Else: Conditions, Elif, Nested Ifs, and Ternary

From the lesson: Python If-Else: Conditions, Elif, Nested Ifs, and Ternary

Every day you make hundreds of decisions. If it's raining, you grab an umbrella. If the traffic light is red, you stop. If your phone battery is below 20%, you look for a charger. These are all conditional decisions - you check something and act based on the result.

Read the lesson

Write a program that checks if a number is even or odd. A variable number is given with the value 7.

Print "even" if the number is even, or "odd" if it's odd.

Expected output:

odd

Hint: A number is even if number % 2 == 0 (the remainder when dividing by 2 is zero).

number = 7
# Check if the number is even or odd

More if else exercises

All Python exercises · 50 practice problems · Control Flow quiz