Python Program to find Armstrong numbers from an array


In this program, you will learn how to find Armstrong numbers from an array in Python.


a = arr.array('i', [121, 153, 234, 370, 344, 371])

Example: How to find Armstrong numbers from an array in Python

import array as arr

a = arr.array('i', [121, 153, 234, 370, 344, 371])

print("Armstrong list are : ", end=" ")

for i in a:
    rev = 0
    num = i
    while num > 0:
        r = num % 10
        rev = rev + r * r * r
        num = int(num / 10)

    if rev == i:
        print(i, end=" ")

Output:

Armstrong list are :  153 370 371