Check Even/Odd Pair
Take two numbers and determine whether both are even, both are odd, or one is even and one is odd.
IntermediatePhase 1 - Level 2: Nested If & Multiple ConditionsExample 7 of 10
check-even-odd-pair.py
1# Take two numbers2num1 = int(input("Enter first number: "))3num2 = int(input("Enter second number: "))45# Check combinations6if num1 % 2 == 0 and num2 % 2 == 0:7 print("Both are even")8elif num1 % 2 != 0 and num2 % 2 != 0:9 print("Both are odd")10else:11 print("One is even, one is odd")
Output
Enter first number: 4 Enter second number: 6 Both are even Enter first number: 3 Enter second number: 5 Both are odd Enter first number: 4 Enter second number: 5 One is even, one is odd
What's going on
Check all possible combinations of even/odd.
Key Concepts:
Both even: num1 % 2 == 0 and num2 % 2 == 0
Both odd: num1 % 2 != 0 and num2 % 2 != 0
Otherwise: one even, one odd
🔗Related Content
- 📖
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- 💻
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum