Ask Question
2 May, 07:21

In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum). Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself). Write a Python3 program to check if a user-entered number is a perfect number or not. Use exception handling to handle invalid inputs.

+5
Answers (1)
  1. 2 May, 09:57
    0
    def the_perfect (n):

    try: #exception handling if n is a negative number

    n > 0

    except: #return - 1 if the error is reached

    return - 1

    else:

    total = 0

    for i in range (1, n) : #for loop from 1 to the target number

    if n % i = = 0:

    total + = i

    return total = = n #should return true if number is perfect number

    print (perfect_number (8))
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers