MASTER YOUR LOGIC BUILDING:Phase 6 - Category 1: Number Logic
Mastering phase 6 - category 1: number logic concepts and implementation.
Number Logic
Why This Matters
Real problems rarely ask for just one thing. A form might check: Is this number positive? Even? Two digits? Does the digit sum divide evenly? Phase 6 is where you combine everything you've learned — loops, conditionals, digits, math — to solve multi-step number puzzles. Think of it like a checklist: each condition is one box to tick.
What You'll Learn
- How to break a complex number problem into smaller checks
- How to combine conditions with
and,or, andnot - How to extract and use digits from a number
- A reliable step-by-step approach for any number logic problem
The Problem-Solving Recipe
When a problem feels overwhelming, follow these five steps:
- Read carefully — underline every condition
- List sub-tasks — what must be true?
- Solve each piece separately — one variable per check
- Combine — use
and/orto join them - Test — try normal cases, edge cases, and "almost valid" cases
Example: A Number Must Pass Four Tests
"Is the number positive, even, two digits, AND does its digit sum come out even?"
Break it apart instead of writing one giant if:
num = int(input("Enter a number: "))
is_positive = num > 0
is_even = num % 2 == 0
is_two_digit = 10 <= num <= 99
digit_sum = 0
temp = abs(num)
while temp > 0:
digit_sum += temp % 10
temp //= 10
sum_is_even = digit_sum % 2 == 0
if is_positive and is_even and is_two_digit and sum_is_even:
print("Passes all checks!")
else:
print("Fails at least one check")
For num = 24: positive ✓, even ✓, two digits ✓, digit sum = 6 (even) ✓.
Useful Building Blocks
Check divisibility:
num % 3 == 0 # divisible by 3?
num % 5 == 0 # divisible by 5?
Count digits without converting to string:
count = 0
temp = abs(num)
while temp > 0:
count += 1
temp //= 10
Reverse digits:
reversed_num = 0
temp = abs(num)
while temp > 0:
reversed_num = reversed_num * 10 + temp % 10
temp //= 10
Common Mistakes & Tips
- Writing one unreadable mega-condition — split into named variables; your future self will thank you
- Forgetting negative numbers — use
abs(num)when working with digits - Off-by-one on ranges — "two-digit" means
10 <= num <= 99, notnum < 100 - Not testing edge cases — try 0, negative numbers, single digits, and numbers that pass 3 of 4 checks
- Tip: Print each boolean (
print(is_even)) while debugging — you'll instantly see which check fails
Practice Focus
- Check if a number is Armstrong (sum of cubes of digits equals the number)
- Find numbers in a range that are divisible by both 3 and 5
- Validate a number against 3+ custom rules you write yourself
- Given a number, print which conditions it passes and which it fails
Number logic is puzzle-solving with code. Take it one condition at a time — you've got this!
Hands-on Examples
Complex Number Validation
# Example: Check if number meets multiple criteria
num = int(input("Enter a number: "))
# Check multiple conditions
is_positive = num > 0
is_even = num % 2 == 0
is_two_digit = 10 <= num <= 99
sum_of_digits = sum(int(d) for d in str(num))
sum_is_even = sum_of_digits % 2 == 0
if is_positive and is_even and is_two_digit and sum_is_even:
print("Number meets all criteria")
else:
print("Number does not meet all criteria")Combine multiple conditions using logical operators. Check each property separately for clarity.
Related Page
🔗Related Content
- 💻
Phase 6 - Practice Problems
Practice Phase 6 concepts with hands-on coding problems
- 📝
Phase 6 - Quiz
Test your Phase 6 understanding with assessment questions
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum