Find Armstrong Numbers in Python | List All Armstrong Numbers from 1 to 1000 Tutorial

Опубликовано: 26 Октябрь 2025
на канале: JR: Educational Channel
23
1

Learn how to find all Armstrong numbers between 1 and 10,000 in Python with this beginner-friendly tutorial! An Armstrong number is a number equal to the sum of its digits raised to the power of the number of digits (e.g., 153 = 1^3 + 5^3 + 3^3). We’ll use a concise list comprehension to list them, finding numbers like 1, 153, 370, and more. Perfect for Python beginners, math enthusiasts, or anyone exploring number theory with coding!

🔍 *What You'll Learn:*
What are Armstrong numbers?
Using list comprehension to find Armstrong numbers
Breaking down the logic for digit power sums
Exploring number theory with Python

💻 *Code Used in This Video:*
Find all Armstrong numbers between 1 and 10,000
armstrong_numbers = [n for n in range(1, 10001) if sum(int(digit)**len(str(n)) for digit in str(n)) == n]
print(armstrong_numbers)
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474]

🌟 *Why Learn About Armstrong Numbers?*
Armstrong numbers are a fun way to explore number theory and coding! They’re also a common problem in programming challenges and interviews. We’ll break down how the list comprehension works: `len(str(n))` gets the number of digits, `int(digit)**len(str(n))` raises each digit to that power, and `sum()` checks if the result equals the original number. Master this, and you’ll be ready for more math-based coding problems!

📚 *Who’s This For?*
Python beginners learning list comprehensions
Students exploring number theory
Coders preparing for programming challenges

👍 Like, subscribe, and comment: What math problem should we code next? Next up: Prime numbers—stay tuned!

#PythonTutorial #ArmstrongNumbers #MathInPython #LearnPython #NumberTheory

Find all Armstrong numbers between 1 and 10,000
An Armstrong number is equal to the sum of its digits raised to the power of the number of digits
armstrong_numbers = [n for n in range(1, 10001) if sum(int(digit)**len(str(n)) for digit in str(n)) == n]
print(armstrong_numbers)
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474]

Example breakdown for 153:
153 has 3 digits, so compute 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
Since 153 == 153, it’s an Armstrong number