From beb5b58df16755e417dad3cf437a3eb061506755 Mon Sep 17 00:00:00 2001 From: JAYANTI MALA <52104784+jayantimala@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:00:21 +0530 Subject: [PATCH] ArmstrongNumber.py check a 3 digit number is Armstrong Number or not. --- ArmstrongNumber.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ArmstrongNumber.py diff --git a/ArmstrongNumber.py b/ArmstrongNumber.py new file mode 100644 index 0000000..a988381 --- /dev/null +++ b/ArmstrongNumber.py @@ -0,0 +1,20 @@ +# Python program to check if the number is an Armstrong number or not + +# take input from the user +num = int(input("Enter a number: ")) + +# initialize sum +sum = 0 + +# find the sum of the cube of each digit +temp = num +while temp > 0: + digit = temp % 10 + sum += digit ** 3 + temp //= 10 + +# display the result +if num == sum: + print(num,"is an Armstrong number") +else: + print(num,"is not an Armstrong number")