A daily exercise, enhance Python is not a problem! ! There are more concise written comment, please let me know!
https://www.cnblogs.com/poloyy/category/1676599.html
topic
If a positive integer equal to itself in addition to all other divisors sum, it is called perfect number. For example: the number of totally 6, * because 6 = 1 + 2 + 3 ; a completely numbers are 28 = 14 + 7 + 4 + 2 + 1 . COMPLETE following number 1000
Problem-solving ideas
Outer loop number within 6-1000
All numbers divisible by number in the current cycle, and add to a list
That sums up whether to compare the current figures are the same
answer
all = [] for num in range(6, 1001): lists = [] for n in range(1, num): if num % n == 0: lists.append(n) if sum(lists) == num: all.append(num) print(all)