Python-Programs
Python-Programs copied to clipboard
Problems
def is_armstrong_number(number): # Convert the number to a string to count its digits num_str = str(number) n = len(num_str)
# Calculate the sum of each digit raised to the nth power
digit_sum = sum(int(digit) ** n for digit in num_str)
# Check if the sum is equal to the original number
return digit_sum == number
Example usage
number = 153 if is_armstrong_number(number): print(f"{number} is an Armstrong number.") else: print(f"{number} is not an Armstrong number.")