Fibonacci Prime Numbers
Find Fibonacci numbers that are prime.
AdvancedPhase 6 - Category 1: Number LogicExample 7 of 10
fibonacci-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# Generate Fibonacci and check prime11print("Fibonacci primes:")12a, b = 0, 113count = 014while count < 20:15 if a > 1 and is_prime(a):16 print(a, end=" ")17 count += 118 a, b = b, a + b19print()
Output
Fibonacci primes: 2 3 5 13 89 233 ...
What's going on
Generate Fibonacci and check primality.
Key Concepts:
Generate Fibonacci sequence
Check if number is prime
Filter prime Fibonacci 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