Challenge: Armstrong Numbers

Test the concepts you've learned so far with a coding exercise.

Problem statement

A number is called an Armstrong number if the sum of the cube of all digits of the number is equal to the number itself. The numbers 371 and 407 are examples of three-digit Armstrong numbers.

33+73+13=3713^3 + 7^3 + 1^3 = 371

43+03+73=4074^3 + 0^3 + 7^3 = 407

For this challenge, you must update the function below to decide if the given three-digit number is an Armstrong number. Your code will work only for three-digit numbers.

Sample input

The function can be provided with any positive number. It should check for its value before deciding if it is an Armstrong number. Example sample inputs are 27, 371, and 655.

Sample output

The function returns a string representing three cases. The value of the returned string can only be InputError, Armstrong, and NotArmstrong.

Coding challenge

You have been provided with some skeleton code. Note that the function signature is incomplete as well. For this challenge, you must complete the function signature and return the correct string depending on whether the number is an Armstrong number or not. You may use the math.Pow function to carry out the cubic calculations.

Try to solve this yourself first. However, if you get stuck, you can click the “Show Solution” button to view the solution. For a detailed explanation, you can go to the next lesson. Good luck!

Get hands-on with 1200+ tech skills courses.