Armstrong Numbers in Range
Find Armstrong numbers in range 1-1000.
AdvancedPhase 6 - Category 1: Number LogicExample 4 of 10
armstrong-numbers-in-range.py
1# Find Armstrong numbers2print("Armstrong numbers 1-1000:")34for num in range(1, 1001):5 # Count digits6 temp = num7 count = 08 while temp > 0:9 count += 110 temp //= 101112 # Calculate sum13 temp = num14 armstrong_sum = 015 while temp > 0:16 digit = temp % 1017 armstrong_sum += digit ** count18 temp //= 101920 if armstrong_sum == num:21 print(num, end=" ")22print()
Output
Armstrong numbers 1-1000: 1 2 3 4 5 6 7 8 9 153 370 371 407
What's going on
Check each number for Armstrong property.
Key Concepts:
Count digits
Calculate sum of digits^count
Compare with number
🔗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