Python Programming

Armstrong Number

Python example to identify user given number is Armstrong or not

7/21/2021
0 views
armstrong-number.pyPython
#!/usr/bin/evn python

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

sum = 0
temp = num

# While loop
while temp > 0:
   digit = temp % 10
   # Multiply 'digit' 3 times
   sum += digit ** 3
   # 'temp' divided 10
   temp //= 10

# Display the result
if num == sum:
   print num,"is an Armstrong number"
else:
   print num,"is not an Armstrong number"



#***** Output *****
# Enter a number: 124
# 124 is not an Armstrong number

#or
# Enter a number: 153
# 153 is an Armstrong number
pythonArmstrong numberpython code

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com