Prime Palindrome Numbers
Find prime palindrome numbers in range.
AdvancedPhase 6 - Category 1: Number LogicExample 5 of 10
prime-palindrome-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 True910def is_palindrome(n):11 return str(n) == str(n)[::-1]1213# Find prime palindromes14print("Prime palindromes 1-1000:")15for num in range(1, 1001):16 if is_prime(num) and is_palindrome(num):17 print(num, end=" ")18print()
Output
Prime palindromes 1-1000: 2 3 5 7 11 101 131 151 181 191 313 353 373 383 727 757 787 797 919 929
What's going on
Check both prime and palindrome properties.
Key Concepts:
Use helper functions
Check prime property
Check palindrome property
Both must be true
🔗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