Python program to check a number is a perfect number or not.
Algorithm:::
Flowchart:::
Program code:::
num=int(input('Enter a number '))
i=1
sum=0
while i<num:
if num%i==0:
sum=sum+i
i=i+1
if sum==num:
print num,'is a perfect number'
else:
print num,'is not a perfect number'
Step 1: Start
Step 2: Read a number, num
Step 3: Assign i=1
Step 4: Assign sum=0
Step 5: Repeat steps 7,8&9 until i=num reaches
Step 7: If num%i==0 goto step 8
Step 8: Compute sum=sum+i
Step 9: Compute i=i+1
Step 10: If sum==num goto step 11 or else goto step 12
Step 11: Print num is a perfect number
Step 12: Print num is not a perfect number
Step 13: Stop
Flowchart:::
Program code:::
num=int(input('Enter a number '))
i=1
sum=0
while i<num:
if num%i==0:
sum=sum+i
i=i+1
if sum==num:
print num,'is a perfect number'
else:
print num,'is not a perfect number'
No comments