From f64af0f7291cd3f6da9484524b3346bfab6e8a54 Mon Sep 17 00:00:00 2001 From: Himesh Nag <39723869+himeshnag@users.noreply.github.com> Date: Tue, 20 Oct 2020 00:27:19 +0530 Subject: [PATCH] Create AmstrongNumber.py --- AmstrongNumber.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 AmstrongNumber.py diff --git a/AmstrongNumber.py b/AmstrongNumber.py new file mode 100644 index 0000000..a988381 --- /dev/null +++ b/AmstrongNumber.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")