Perfect Numbers: Missing perfect-square test case allows incorrect solutions to pass

Hi! I’d like to report a test coverage gap in the Python track exercise (Perfect Numbers).

In short: I was able to submit a solution that does not handle all cases correctly, yet it still passed the test suite. The root cause is that the tests appear to miss some key perfect-square cases.

My approach was to iterate divisors only up to √n and use divisor pairs: if i divides n, then n//i also divides n. For any divisor pair (i, n//i), at least one of them is ≤ √n, so scanning up to √n is sufficient to discover all divisor pairs.

However, I wrote a loop like this:

limit = math.sqrt(number)
for i in range(1, math.ceil(limit)):
    ...

In Python, the upper bound of range is exclusive. When number is a perfect square, sqrt(number) is an integer k, but k is not included in the loop, so the factor k is missed (and for perfect squares it should be counted exactly once). This can change the classification result.

Counterexample: 196 = 14^2
Proper divisors of 196 are 1, 2, 4, 7, 14, 28, 49, 98, which sum to 203. Since 203 > 196, 196 should be classified as abundant.
If the square-root factor 14 is omitted, the sum becomes 203 − 14 = 189, which would incorrectly classify 196 as deficient.

Suggestion: add at least one perfect-square test case that exposes this issue (e.g., 196), or add a dedicated test for perfect squares, to prevent incorrect implementations from passing.

Hi @Wr3ncH513 :wave:

Welcome to the Exercism forums!

Thank you for posting your issue.

The Python track pulls the test cases for the majority of its practice exercises from a common cross-track repository called problem-specifications. Perfect Numbers is one of those exercises.

Proposed changes for problem-specifications are discussed cross-track, and need consensus from at least three track maintainers. Because of this, I am moving your topic out of Python and into a more general forum.

A post was split to a new topic: Perfect Numbers Perfect Square Test Cases