Check Middle Digit
Take a 3-digit number and determine if the middle digit is the largest, smallest, or neither.
IntermediatePhase 1 - Level 3: Math and Number LogicExample 2 of 10
check-middle-digit.py
1# Take 3-digit number2num = int(input("Enter a 3-digit number: "))34# Extract digits5digit1 = num // 1006digit2 = (num // 10) % 107digit3 = num % 1089# Check middle digit10if digit2 > digit1 and digit2 > digit3:11 print("Middle digit is largest")12elif digit2 < digit1 and digit2 < digit3:13 print("Middle digit is smallest")14else:15 print("Middle digit is neither largest nor smallest")
Output
Enter a 3-digit number: 152 Middle digit is largest Enter a 3-digit number: 251 Middle digit is smallest Enter a 3-digit number: 123 Middle digit is neither largest nor smallest
What's going on
Compare middle digit with first and third digits.
Key Concepts:
Extract all three digits
Check if middle > both others (largest)
Check if middle < both others (smallest)
Otherwise, it's neither
🔗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