Armstrong number - Range - Python
Armstrong number - Range - Python
Hello Friends...
Welcome today...
I show you, how to find Armstrong number between range
Welcome today...
I show you, how to find Armstrong number between range
Easy code
Let's see
CODE 1:
def armStrong(a):
n = len(str(a))
sum = 0
for i in str(a):
sum += pow(int(i),n)
return sum
a = int(input('Enter range from 10 to: '))
arm = []
for i in range(150,a+1):
result = armStrong(i)
if result == i:
arm.append(i)
print(arm)
----
CODE 2:
# Check given code Armstrong or not
def armStrong(a):
n = len(str(a))
sum = 0
for i in str(a):
sum += pow(int(i),n)
return sum
a = int(input('Enter any number to check: '))
result = armStrong(a)
if result == a:
print(f'{a} is a armStrong number')
else:
print(f'{a} is not a armStrong number')
-----
By
PyKAR
PyKAR
Comments
Post a Comment