Armstrong Numbers between two integers | PYTHON program to find Armstrong numbers in a range ; Prints Armstrong Numbers in given range ; number of digits calculation ; compute sum of nth power of ; checks if number i is equal to the sum of nth power of its digits ; Driver code
import math NEW_LINE def findArmstrong ( low , high ) : NEW_LINE INDENT for i in range ( low + 1 , high ) : NEW_LINE INDENT x = i NEW_LINE n = 0 NEW_LINE while ( x != 0 ) : NEW_LINE INDENT x = x / 10 NEW_LINE n = n + 1 NEW_LINE DEDENT pow_sum = 0 NEW_LINE x = i NEW_LINE while ( x != 0 ) : NEW_LINE INDENT digit = x % 10 NEW_LINE pow_sum = pow_sum + math . pow ( digit , n ) NEW_LINE x = x / 10 NEW_LINE DEDENT if ( pow_sum == i ) : NEW_LINE INDENT print ( str ( i ) + " ▁ " ) , NEW_LINE DEDENT DEDENT DEDENT num1 = 100 NEW_LINE num2 = 400 NEW_LINE findArmstrong ( num1 , num2 ) NEW_LINE print ( " " ) NEW_LINE