pythonExample100/JCP019.py

26 lines
544 B
Python
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

'''
【程序19】
题目一个数如果恰好等于它的因子之和这个数就称为“完数”。例如6=123.编程
   找出1000以内的所有完数。
1. 程序分析:请参照程序<--上页程序14.
2.程序源代码:
'''
from sys import stdout
for j in range(2,1001):
k = []
n = -1
s = j
for i in range(1,j):
if j % i == 0:
n += 1
s -= i
k.append(i)
if s == 0:
print j
for i in range(n):
stdout.write(k[i])
stdout.write(' ')
print k[n]