Python Compiler
import math num = int(input("Enter a (int) number: ")); copyNum = num; digits = 0; remainder = 0; total = 0; #find number of digits in num variable while(copyNum != 0): digits += 1; copyNum = math.floor(copyNum / 10); copyNum = num; #slice the numbers from last digits while(copyNum != 0): remainder = copyNum % 10 total += pow(remainder, digits) copyNum = math.floor(copyNum / 10) #result if(num == total): print("%d is an armstrong number" % num); else: print("%d is not an armstrong number" % num);
OUTPUT
Enter a (int) number: 407
407 is an armstrong number
×

Save as Private