Prime Triplets
Find prime triplets (three consecutive primes with pattern).
AdvancedPhase 6 - Category 3: Loop & Conditional MixExample 10 of 10
prime-triplets.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 prime triplets11print("Prime triplets (p, p+2, p+6) up to 100:")12for num in range(2, 95):13 if is_prime(num) and is_prime(num + 2) and is_prime(num + 6):14 print(f"({num}, {num + 2}, {num + 6})", end=" ")15print()
Output
Prime triplets (p, p+2, p+6) up to 100: (5, 7, 11) (11, 13, 17) (17, 19, 23) (41, 43, 47)
What's going on
Check if three numbers form prime triplet.
Key Concepts:
Check if num, num+2, num+6 are all prime
Pattern: (p, p+2, p+6)
All must be prime
🔗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