Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # program to check if a given number is a armstrong number or not
- def armstrong(number):
- n = number
- myNum = []
- while n != 0:
- temp = n%10
- n = int(n/10)
- myNum.append(temp)
- for i in range(len(myNum)):
- myNum[i] = myNum[i] ** 3
- sumation = sum(myNum)
- if sumation == number:
- return True
- else:
- return False
- def checkArmstrong(upper,lower):
- for i in range(lower, upper+1):
- isArmstrong = armstrong(i)
- if isArmstrong:
- print(i)
- # main function
- cont = True
- while cont:
- print("The following choices are availiable : ")
- print("1.Check if a number is an Armstrong number or not")
- print("2.Print all armstrong numbers in a given range")
- choice = int(input("Enter your choice : "))
- while choice > 2 or choice < 0:
- print("Wrong input!")
- choice = int(input("Enter your choice : "))
- if choice == 1:
- number = int(input("Enter the Number : "))
- isArmstrong = armstrong(number)
- if isArmstrong:
- print("The entered number is an Armstrong Number.")
- else:
- print("The entered number is not an Armstrong Number.")
- elif choice == 2:
- upper = int(input("Enter the upper limit : "))
- lower = int(input("Enter the lower limit : "))
- checkArmstrong(upper, lower)
- n = int(input("Do you want to continue (1/0): "))
- if n == 0:
- cont = False
- print()
Add Comment
Please, Sign In to add comment