Code Library


Armstrong number :
   
Armstrong number is the number in any given number base, which forms the total of the same number, when each of its digits is raised to the power of the number of digits in the number. It is of special interest to new programmers and those learning a new programming language because of the way the number behaves in a given number base. for example, 153 is an armstrong number because 1^3 + 5^3 + 3^3 = 153. armstrong number is also known as narcissistic number or plus perfect number3. the number of digits can vary depending on the number base135.

num = int(input("Enter a number: "))
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")
Enter a number: 7
7 is not an Armstrong number