03
Phase 1 - Level 3: Math and Number Logic
Chapter 3 • Intermediate
75 min
Phase 1 - Level 3: Math and Number Logic
Introduction
This level combines conditional thinking with mathematical operations. You'll work with digits, number properties, and mathematical relationships.
Working with Digits
To extract digits from a number:
- Use modulo (%) to get last digit
- Use integer division (//) to remove last digit
- Repeat to process all digits
Number Properties
Common checks:
- Perfect Square: Check if a number is a perfect square
- Digit Analysis: Extract and analyze individual digits
- Number Range: Check if number falls in specific ranges
- Mathematical Relationships: Check arithmetic/geometric progressions
Key Techniques
- Digit Extraction: num % 10 gives last digit, num // 10 removes last digit
- Perfect Square Check: Check if square root is an integer (without using sqrt)
- Digit Comparison: Compare digits within a number
- Range Validation: Check if number is within [min, max]
Common Patterns
- Extract digits and check properties
- Compare digits within a number
- Check mathematical relationships
- Validate number ranges
Hands-on Examples
Check if All Digits are Distinct
# Take a 3-digit number
num = int(input("Enter a 3-digit number: "))
# Extract digits
digit1 = num // 100
digit2 = (num // 10) % 10
digit3 = num % 10
# Check if all distinct
if digit1 != digit2 and digit2 != digit3 and digit1 != digit3:
print("All digits are distinct")
else:
print("Digits are not all distinct")Extract each digit using integer division and modulo, then compare all pairs to ensure they are different.
Related Tutorials
🔗Related Content
- 💻
Phase 1 - Practice Problems
Practice Phase 1 concepts with hands-on coding problems
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with assessment questions
- ➡️
Phase 2 - Get Started
Continue to Phase 2 after mastering Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum