From 5ef7e350927b49ed72b6f6650bd8a1d838604870 Mon Sep 17 00:00:00 2001 From: Aditya-K477 Date: Tue, 1 Oct 2024 14:25:22 +0530 Subject: [PATCH] Create To Check Armstrong Num.py --- To Check Armstrong Num.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 To Check Armstrong Num.py diff --git a/To Check Armstrong Num.py b/To Check Armstrong Num.py new file mode 100644 index 0000000..70362f5 --- /dev/null +++ b/To Check Armstrong Num.py @@ -0,0 +1,20 @@ +# Function to check if a number is an Armstrong number +def is_armstrong(number): + # Convert the number to string to easily find the length (number of digits) + num_str = str(number) + num_digits = len(num_str) + + # Calculate the sum of each digit raised to the power of the number of digits + sum_of_powers = sum(int(digit) ** num_digits for digit in num_str) + + # Check if the sum equals the original number + return sum_of_powers == number + +# Input from the user +num = int(input("Enter a number: ")) + +# Check and display if the number is Armstrong or not +if is_armstrong(num): + print(f"{num} is an Armstrong number.") +else: + print(f"{num} is not an Armstrong number.")