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/ Explanation:

Enter the value of N : 4

6 28 496 8128 

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad