logo CodeStepByStep logo


Language/Type: Python for

Write a function named armstrong_numbers that accepts an integer n as a parameter and prints all n-Armstrong numbers. An n-Armstrong number is a number containing exactly n digits where the sum of each digit raised to the nth power equals the number itself. For example, 153 is a 3-Armstrong number because 13 + 53 + 33 = 153. The call of armstrong_numbers(3) should print the following console output:

153 370 371 407

If n is 0 or negative, or if there are no n-Armstrong numbers, print no output.

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.