Python-Programs icon indicating copy to clipboard operation
Python-Programs copied to clipboard

Problems

Open VittalKumar23 opened this issue 2 years ago • 0 comments

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.")

VittalKumar23 avatar Oct 12 '23 15:10 VittalKumar23