Conversation

VittalKumar23

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

@VittalKumar23VittalKumar23 changed the title Create armstrong.py Problems Oct 13, 2023
Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

@VittalKumar23