From 86b7a6198b5dec2c48d65ddb8d50f065be8dd943 Mon Sep 17 00:00:00 2001 From: Niraj Dhalani <32194632+nirajdhalani@users.noreply.github.com> Date: Tue, 20 Oct 2020 14:46:28 +0530 Subject: [PATCH] Create armstrongno.py Check Armstrong number (for 3 digits) --- armstrongno.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 armstrongno.py diff --git a/armstrongno.py b/armstrongno.py new file mode 100644 index 0000000..a988381 --- /dev/null +++ b/armstrongno.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")