I was asked to find three consecutive perfect numbers (i.e. numbers which factors(including 1 and excluding itself) sum up to be itself) after 6. Here is my attempt:
# Find three consecutive perfect numbers after 6
def f(x):
"Find the sum of all factors."
factors = []
for i in range (1,x-1):
if x%i == 0:
factors.append (i)
else:
pass
return sum(factors)
counts = 0
perfect_numbers = []
x = 6
while counts <= 2:
x += 1
if x == f(x):
perfect_numbers.append (x)
counts += 1
else:
pass
print(perfect_numbers)
As I run it, nothing shows up. I know there could be a really trivial mistake however I spent whole day searching for it and got nothing. Please help.