Write a program to print perfect numbers from the given list of integers


Topic: Write a program to print perfect numbers from the given list of integers

Solution

def checkPerfectNum(n) :
	i = 2;sum = 1;
	while(i <= n//2 ) :
		if (n % i == 0) :
			sum += i			
		
		i += 1
		if sum == n :
			print(n,end=' ')
if __name__ == "__main__" :
	print("Enter list of integers: ")
	list_of_intgers = list(map(int,input().split()))
	print("Given list of integers:",list_of_intgers)
	print("Perfect numbers present in the list is: ")
	for num in list_of_intgers :
		checkPerfectNum(num)
        



List all Python Programs