Programming Examples

Python program to print first n perfect numbers


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 

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz