Beginner Exercises for If-Else Statements in Python

2 min read

1. Even or Odd
Ask the user for a number. Print if it's even or odd.
2. Greater Number
Ask the user to enter two numbers. Print the greater one.
3. Pass or Fail
Ask the user for a score.
If score >= 50, print “Pass”. Otherwise, print “Fail”.
4. Temperature Check
Ask the user for the temperature.
Print:
“Hot” if >30
“Warm” if between 20–30
“Cold” if <20
5. Leap Year Checker
Ask the user for a year.
Check if it’s a leap year:
- Divisible by 4, not divisible by 100 unless divisible by 400.
✅ ANSWERS
1. Even or Odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
2. Greater Number
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a > b:
print("Greater number is", a)
else:
print("Greater number is", b)
3. Pass or Fail
score = int(input("Enter your score: "))
if score >= 50:
print("Pass")
else:
print("Fail")
4. Temperature Check
temp = int(input("Enter temperature: "))
if temp > 30:
print("Hot")
elif temp >= 20:
print("Warm")
else:
print("Cold")
5. Leap Year Checker
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap year")
else:
print("Not a leap year")
0
Subscribe to my newsletter
Read articles from Arzath Areeff directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Arzath Areeff
Arzath Areeff
I co-founded digizen.lk to promote online safety and critical thinking. Currently, I’m developing an AI app to fight misinformation. As Founder and CEO of ideaGeek.net, I help turn startup dreams into reality, and I share tech insights and travel stories on my YouTube channels, TechNomad and Rz Omar.