Nov-23-2020, 09:50 PM
Gentlemans, do you have any suggestions why this code doesn't output proper values?
When I write end = 100 it outputs:
[6, 24, 28]
24 is not a perfect number.
When I write end = 100 it outputs:
[6, 24, 28]
24 is not a perfect number.
def perfect_number(end = 100): lista = [] for n in range(2, end): sum = 0 for x in range(1, n): if n % x == 0: sum += x if sum == n: lista.append(n) sum = 0 return lista print(perfect_number())