An Armstrong number of three digits is an integer in which the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 33 + 73 + 13 = 371. Write a program to check whether a number is an Armstrong number or not.

Source Code

number = int(input("Enter a number: "))
original_number = number  # Save the original number for display

# Calculate the sum of cubes of digits
sum_of_cubes = 0
while number > 0:
    digit = number % 10
    sum_of_cubes += digit ** 3
    number = number // 10

# Check if the number is an Armstrong number
if original_number == sum_of_cubes:
    print(original_number, "is an Armstrong number.")
else:
    print(original_number, "is not an Armstrong number.")

Output

Sample output#1
Enter a number: 153
153 is an Armstrong number.
Sample output#2
Enter a number: 123
123 is not an Armstrong number.