
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to generate armstrong numbers in Python?
Any three digit number is called an Armstrong number of sum of cube of its digits equals the number itself. In order to check if a number satisfies this condition, each digit from it is successively separated from right and its cube is cumulatively added. In the end if the sum is found to be equal to original number, it is called Armstrong number.
Example
Following Python code prints all armstrong numbers between 100 to 999
for num in range(100,1000): temp=num sum=0 while temp>0: digit=temp%10 sum=sum+digit**3 temp=temp//10 if sum==num: print (num)
Output
The output is list of armstrong numbers
153 370 371 407
- Related Articles
- How to print Narcissistic(Armstrong) Numbers with Python?
- How to generate prime numbers using Python?
- How to generate non-repeating random numbers in Python?
- How to generate pyramid of numbers using Python?
- How does Python generate random numbers?
- How to use Python Numpy to generate Random Numbers?
- How can we generate Strong numbers in Python?
- Write a program in Python to filter armstrong numbers in a given series
- Generate pseudo-random numbers in Python
- Python module to Generate secure random numbers
- How to generate Prime Numbers in JavaScript?
- Program to generate first n lexicographic numbers in python
- C Program for Armstrong Numbers
- Armstrong Numbers between two integers?
- Armstrong Number in Python

Advertisements