perfect number in number theory a perfect number is a positive integer that is equal to the sum of its positive divisors excluding the number itself for example 6 divisors1 2 3 6 excluding 6 the sumdivisors is 1 2 3 6 so 6 is a perfect number other examples of perfect numbers 28 486 https en wikipedia orgwikiperfectnumber check if a number is a perfect number a perfect number is a positive integer that is equal to the sum of its proper divisors excluding itself args number the number to be checked returns true if the number is a perfect number false otherwise start from 1 because dividing by 0 will raise zerodivisionerror a number at most can be divisible by the half of the number except the number itself for example 6 is at most can be divisible by 3 except by 6 itself examples perfect27 false perfect28 true perfect29 false perfect6 true perfect12 false perfect496 true perfect8128 true perfect0 false perfect1 false perfect12 34 traceback most recent call last valueerror number must be an integer perfecthello traceback most recent call last valueerror number must be an integer check if a number is a perfect number a perfect number is a positive integer that is equal to the sum of its proper divisors excluding itself args number the number to be checked returns true if the number is a perfect number false otherwise start from 1 because dividing by 0 will raise zerodivisionerror a number at most can be divisible by the half of the number except the number itself for example 6 is at most can be divisible by 3 except by 6 itself examples perfect 27 false perfect 28 true perfect 29 false perfect 6 true perfect 12 false perfect 496 true perfect 8128 true perfect 0 false perfect 1 false perfect 12 34 traceback most recent call last valueerror number must be an integer perfect hello traceback most recent call last valueerror number must be an integer
def perfect(number: int) -> bool:
    
    if not isinstance(number, int):
        raise ValueError("number must be an integer")
    if number <= 0:
        return False
    return sum(i for i in range(1, number // 2 + 1) if number % i == 0) == number


if __name__ == "__main__":
    from doctest import testmod

    testmod()
    print("Program to check whether a number is a Perfect number or not...")
    try:
        number = int(input("Enter a positive integer: ").strip())
    except ValueError:
        msg = "number must be an integer"
        print(msg)
        raise ValueError(msg)

    print(f"{number} is {'' if perfect(number) else 'not '}a Perfect Number.")