From fef8b853000619d7706c616d51c8618b1e434362 Mon Sep 17 00:00:00 2001 From: Bhavdeep Singh <131872477+Bhavdeepq@users.noreply.github.com> Date: Wed, 1 Oct 2025 18:57:20 +0530 Subject: [PATCH 1/2] Create armstrong.py --- armstrong.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 armstrong.py diff --git a/armstrong.py b/armstrong.py new file mode 100644 index 000000000000..22792f5d22a3 --- /dev/null +++ b/armstrong.py @@ -0,0 +1,33 @@ + +try: + # Get input from the user. + num = int(input("Enter a number to check if it's an Armstrong number: ")) + + # An Armstrong number must be positive. + if num < 0: + print("Please enter a positive integer.") + else: + # Convert the number to a string to find the number of digits (the order). + s_num = str(num) + order = len(s_num) + + # Initialize the sum. + sum_of_powers = 0 + + # A temporary variable to work with. + temp = num + + # Calculate the sum of each digit raised to the power of the order. + while temp > 0: + digit = temp % 10 + sum_of_powers += digit ** order + temp //= 10 + + # Check if the original number is equal to the sum. + if num == sum_of_powers: + print(f"{num} is an Armstrong number.") + else: + print(f"{num} is not an Armstrong number.") + +except ValueError: + print("Invalid input. Please enter an integer.") From 7ed50e50ac62dc46d0a01715324ed7f70bd31299 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 May 2026 17:32:34 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- armstrong.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/armstrong.py b/armstrong.py index 22792f5d22a3..d9b3487bb6ef 100644 --- a/armstrong.py +++ b/armstrong.py @@ -1,8 +1,7 @@ - try: # Get input from the user. num = int(input("Enter a number to check if it's an Armstrong number: ")) - + # An Armstrong number must be positive. if num < 0: print("Please enter a positive integer.") @@ -10,19 +9,19 @@ # Convert the number to a string to find the number of digits (the order). s_num = str(num) order = len(s_num) - + # Initialize the sum. sum_of_powers = 0 - + # A temporary variable to work with. temp = num - + # Calculate the sum of each digit raised to the power of the order. while temp > 0: digit = temp % 10 - sum_of_powers += digit ** order + sum_of_powers += digit**order temp //= 10 - + # Check if the original number is equal to the sum. if num == sum_of_powers: print(f"{num} is an Armstrong number.")