Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Armstrong Number Checking by Khrystyna11
def is_armstrong(num: int) -> bool:
sum_num = 0
str_num = str(num)
power_num = len(str_num)
for i in str_num:
power = int(i) ** power_num
sum_num += power
if sum_num == num:
return True
return False
print("Example:")
print(is_armstrong(11))
# These "asserts" are used for self-checking
assert is_armstrong(153) == True
assert is_armstrong(370) == True
assert is_armstrong(947) == False
assert is_armstrong(371) == True
assert is_armstrong(407) == True
assert is_armstrong(163) == False
assert is_armstrong(100) == False
assert is_armstrong(8208) == True
assert is_armstrong(930) == False
assert is_armstrong(4) == True
print("The mission is done! Click 'Check Solution' to earn rewards!")
Aug. 9, 2024
Comments: