Menu Close

Find the Perfect Number

In number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3, and 1 + 2 + 3 = 6, so 6 is a perfect number.

def perfectnumber(numbr):
	s=0
	i=1
	while(i<=10000):
		temp=numbr%i
		if(temp==0 and i!=numbr):
			s+=i
		i+=1
	if(s==numbr):
		return 1
	else:
		return 0




numbr=int(input('Enter a Number : '))
if(perfectnumber(numbr)==1):
	print("The number is a perfect number")
else:
	print("The number is not a perfect number")

exec.on linux terminal

More Codes to Fcuk