To generate armstrong numbers in python, you have to ask from user to enter the interval or simply enter starting and ending number to generate armstrong numbers in between the interval given by the user as shown in the program given below.
Following python program ask from user to enter interval to generate and print armstrong numbers between the interval entered by the user:
# Python Program - Generate Armstrong Numbers while True: print("Enter 'x' for exit.") print("Enter the interval (starting and ending number): ") start = input() end = input() if start == 'x': break else: lower = int(start) upper = int(end) for num in range(lower, upper+1): tot = 0 temp = num while temp != 0: dig = temp % 10 tot += dig ** 3 temp //= 10 if num == tot: print(num) print("\n")
Here is the sample run of the above python program to illustrate how to generate armstrong numbers:
You may also like to learn or practice the same program in other popular programming languages: