提取输入的正整数的每一位数字,然后进行计算
def test(N):
temp = N
list = []
# 判断大于10的,应该一位数肯定是符合条件的
while temp / 10.0 > 0:
s = temp % 10
list.append(s)
temp = temp // 10
sum = 0
for item in list:
sum += item ** len(list)
if sum == N:
return True
else:
return False
res = test(153)
print(res)
def test2(N):
strN = str(N)
list = [int(item) for item in strN]
sum = 0
for item in list:
sum += item ** len(list)
return sum == N
res = test2(153)
print(res)
def test2(N):
_list = list(str(N))
sum = 0
for item in _list:
sum += int(item) ** len(_list)
return sum == N
res = test2(153)
print(res)