

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Check Armstrong Number
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given an integer n , we need to check that the given integer is an armstrong number.
A positive integer is called an Armstrong number of order n if
abcd... = a^n + b^n + c^n + d^n + …
Here we will be discussing the brute-force approach for an armstrong number of 3 digits and hence of order three.
To check the armstrong number of order n we need to replace 3 by the corresponding order value in line number 7.
Now let’s see the implementation −
Example
num = 221 sum_ = 0 # temp = num while temp > 0: digit = temp % 10 sum_ += digit ** 3 temp //= 10 # if num == sum_: print(num,"is an Armstrong number") else: print(num,"is not an Armstrong number")
Output
221 is not an Armstrong number
All variables and functions are declared in the global scope as shown in the figure below.
Conclusion
In this article, we learned about the approach to check whether a given number is an armstrong number or not.
- Related Questions & Answers
- C++ Program to Check Armstrong Number
- C Program to Check Armstrong Number?
- Java Program to Check Armstrong Number
- Java Program to Check Armstrong Number between Two Integers
- Java program to check whether the given number is an Armstrong number
- Armstrong Number in Python
- Write a C# program to check if the entered number is Armstrong number?
- C# Program to Check Whether the Entered Number is an Armstrong Number or Not
- Check the number is Armstrong or not using C
- C++ Program to Display Armstrong Number Between Two Intervals
- Java Program to Display Armstrong Number Between Two Intervals
- Armstrong number in Java.
- Python Program to Check Prime Number
- How to Find Armstrong Number in an Interval using Python?
- C Program for Armstrong Numbers
Advertisements