Site icon T4Tutorials.com

Armstrong number in Python

Write a Program in Python to find Armstrong numbers.

Armstrong number C++ Program

# Python program to check if the number is an Armstrong number or not

# take input from the user
num = int(input("Please Enter a number: "))

# initialize Result
Result = 0

# this code will find the Result of the cube of each digit
T4Tutorials = num
while T4Tutorials > 0:
   digit = T4Tutorials % 10
   Result += digit ** 3
   T4Tutorials //= 10

# Show the result
if num == Result:
   print("Congaratulations! ", num,"is an Armstrong number")
else:
   print("Sorry! ",num,"is not an Armstrong number")

Output

Please Enter a number: 5
Sorry! 5 is not an Armstrong number

Exit mobile version