Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Fifth solution in Clear category for Perfect Number Checking by freeman_lex
def is_perfect(n: int) -> bool:
divisors = {1}
for i in range(2, int(n**0.5) + 1):
quot, rem = divmod(n, i)
if not rem:
divisors |= {quot, i}
return sum(divisors) == n
print("Example:")
print(is_perfect(3))
# These "asserts" are used for self-checking
assert is_perfect(6) == True
assert is_perfect(2) == False
assert is_perfect(28) == True
assert is_perfect(20) == False
assert is_perfect(496) == True
assert is_perfect(30) == False
assert is_perfect(8128) == True
assert is_perfect(100) == False
assert is_perfect(500) == False
assert is_perfect(1000) == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
Sept. 26, 2023
Comments: