Ask Question
13 March, 02:24

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.

+2
Answers (1)
  1. 13 March, 04:40
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers