Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Perfect Number Checking by kavishhh
def is_perfect(n: int) -> bool:
# your code here
if n <= 1:
return False
divisors_sum = 1
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
divisors_sum += i
other_divisor = n // i
if other_divisor != i:
divisors_sum += other_divisor
return divisors_sum == 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!")
Oct. 20, 2025
Comments: