- 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
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
Python Program to Check Armstrong Number
In this article, we will learn about the solution and approach to solve the given 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 −
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")
221 is not an Armstrong number
All variables and functions are declared in the global scope as shown in the figure below.
In this article, we learned about the approach to check whether a given number is an armstrong number or not.
- Related Articles
- C++ Program to Check Armstrong Number
- C Program to Check Armstrong Number?
- Java Program to Check Armstrong Number
- Swift Program to Check Armstrong Number
- Haskell Program to Check Armstrong Number
- Golang Program to Check For Armstrong Number
- Java Program to Check Armstrong Number between Two Integers
- Kotlin Program to Check Armstrong Number between Two Integers
- Haskell program to check armstrong number between two integers
- Java program to check whether the given number is an Armstrong number
- 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
- Armstrong Number in Python
- How to Check Armstrong Number between Two Integers in Golang?
- Python Program to Check Prime Number