Exercise: Perfect numbersΒΆ
Perfect numbers are positive integers that are equal to the sum of their divisors. Here we have provided example Python and R scripts that should print all of the perfect numbers up to 1,000.
You can download each script to debug on your own computer:
But there's a problem ...
If we run these scripts, we see that they don't print anything:
How should we begin investigating?
Interactive debugger sessions
If your editor supports running a debugger, use this feature! See these examples for RStudio, PyCharm, Spyder, and VS Code.
Some initial thoughts ...
-
Are we actually running the
main()function at all? -
The
main()function is almost certainly not the cause of this error. -
The
is_perfect()function is very simple, so it's unlikely to be the cause of this error. -
The
divisors_of()function doesn't look obviously wrong. -
But there must be a mistake somewhere!
-
Let's use a debugger to investigate.