Computer Science, asked by Byehi, 7 months ago

Can someone help me write a Python program to accept a number and check if it's perfect using 'while' loop?

Answers

Answered by ritabratadas121
1

Answer:

def isPerfect( n ):  

     

   # To store sum of divisors  

   sum = 1

     

   # Find all divisors and add them  

   i = 2

   while i * i <= n:  

       if n % i == 0:  

           sum = sum + i + n/i  

       i += 1

     

   # If sum of divisors is equal to  

   # n, then n is a perfect number  

     

   return (True if sum == n and n!=1 else False)

input = int(input("Enter a number... "))

if isPerfect(input):

       print("It is a Perfect Number")

else:

       print("It is not a perfect number")

HOPE IT HELPS U. PLS MARK MY ANSWER AS BRAINLIEST.

Similar questions