How to Check Armstrong Number in Python


In this example, we will learn how to check if a number is Armstrong or not with Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input("Enter any number: "))
temp = list(map(int, str(n)))
a = list(map(lambda x : x ** len(str(n)), temp))
if sum(a) == n:
    print("The number is an armstrong number. ")
else:
    print("The number isn't an arsmtrong number. ")

Output:

Enter any number: 25
The number isn't an arsmtrong number.

Enter any number: 370
The number is an armstrong number.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement