n=int(input('enter number:'))
summ=0
for i in range(1,n): # (1,n//2+1) all factors b/w 1 and half of number if excludes n itself
if n%i==0:
summ+=i
if summ==n:
print(n,'is perfect number')
else:
print(n,'is not perfect number')
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter