All Palindrome Numbers 1-500
Print all palindrome numbers from 1 to 500.
AdvancedPhase 2 - Level 5: Logical Loop CombinationsExample 3 of 12
all-palindrome-numbers-1-500.py
1# Print palindrome numbers2print("Palindrome numbers 1-500:")3for num in range(1, 501):4 # Reverse number5 original = num6 reversed_num = 07 temp = num8 while temp > 0:9 reversed_num = reversed_num * 10 + temp % 1010 temp //= 101112 # Check palindrome13 if original == reversed_num:14 print(num, end=" ")15print()
Output
Palindrome numbers 1-500: 1 2 3 ... 11 22 33 ... 101 111 121 ... 494
What's going on
Check each number for palindrome property.
Key Concepts:
Reverse each number
Compare with original
Print if palindrome
🔗Related Content
- 📖
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- 💻
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum