MCPcopy Create free account
hub / github.com/geekcomputers/Python / isPerfectNumber

Function isPerfectNumber

primelib/primelib.py:539–560  ·  view source on GitHub ↗

input: positive integer 'number' > 1 returns true if 'number' is a perfect number otherwise false.

(number)

Source from the content-addressed store, hash-verified

537
538
539def isPerfectNumber(number):
540 """
541 input: positive integer 'number' > 1
542 returns true if 'number' is a perfect number otherwise false.
543 """
544
545 # precondition
546 assert isinstance(number, int) and (number > 1), (
547 "'number' must been an int and >= 1"
548 )
549
550 divisors = getDivisors(number)
551
552 # precondition
553 assert (
554 isinstance(divisors, list)
555 and (divisors[0] == 1)
556 and (divisors[len(divisors) - 1] == number)
557 ), "Error in help-function getDivisiors(...)"
558
559 # summed all divisors up to 'number' (exclusive), hence [:-1]
560 return sum(divisors[:-1]) == number
561
562
563# ------------------------------------------------------------

Callers

nothing calls this directly

Calls 1

getDivisorsFunction · 0.85

Tested by

no test coverage detected