Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions To Check Armstrong Num.py
Original file line number Diff line number Diff line change
@@ -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.")