这是我到目前为止所拥有的:
def sumMultiple(num):
sum = 0
for i in range(1, num//2+1):
if (num % i == 0):
sum += i
return sum
for in in range(1, 100000):
if(sumMultiple(i) == i):
print(i)
答案 0 :(得分:1)
您可以使用在内部循环中迭代的全局变量。
iterationCount = 0
def sumMultiple(num):
global iterationCount
sum = 0
for i in range(1, num//2+1):
if num % i == 0:
sum += i
iterationCount++
return sum
for i in range(1, 1000):
if sumMultiple(i) == i:
print(i)
print("Total iterations ", iterationCount)