Semi-Prime Numbers
Find semi-prime numbers (product of two primes).
AdvancedPhase 6 - Category 3: Loop & Conditional MixExample 9 of 10
semi-prime-numbers.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 semi-primes11print("Semi-prime numbers 1-100:")12for num in range(1, 101):13 found = False14 for i in range(2, int(num ** 0.5) + 1):15 if num % i == 0:16 j = num // i17 if is_prime(i) and is_prime(j):18 found = True19 break20 if found:21 print(num, end=" ")22print()
Output
Semi-prime numbers 1-100: 4 6 9 10 14 15 21 22 25 26 ...
What's going on
Check if number is product of two primes.
Key Concepts:
Find factors
Check if both factors are prime
Semi-prime property
🔗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