Programming Examples
Python program to print first n perfect numbers

Write a Python program which accept the value of n from user and print first n Perfect Numbers.
n=int(input("Enter the value of N : "))
count=0
a=1;
while count<=n:
  sum=0
  for b in range (1,(a//2)+1):
    if a%b==0:
      sum=sum+b
  if sum==a:
    print(a ,end=' ')
    count+=1
  a+=1
Output
Enter the value of N : 4
6 28 496 8128Â