Numbers with Prime Digit Sum
Find numbers whose digit sum is prime.
AdvancedPhase 6 - Category 1: Number LogicExample 6 of 10
numbers-with-prime-digit-sum.py
1# Helper function2def is_prime(n):3 if n < 2:4 return False5 for i in range(2, int(n ** 0.5) + 1):6 if n % i == 0:7 return False8 return True910# Find numbers11print("Numbers 1-100 with prime digit sum:")12for num in range(1, 101):13 digit_sum = sum(int(d) for d in str(num))14 if is_prime(digit_sum):15 print(num, end=" ")16print()
Output
Numbers 1-100 with prime digit sum: 2 3 5 7 11 12 14 16 20 21 ...
What's going on
Calculate digit sum and check if prime.
Key Concepts:
Calculate sum of digits
Check if sum is prime
Filter numbers
🔗Related Content
- 📖
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- 📝
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- 💻
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum