Skip to content

Bbp formula #1989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
Updated aliquot_sum.py
  • Loading branch information
ken437 committed May 15, 2020
commit 2a1116723baf7166007dae0e7675cbe4cbffa876
24 changes: 15 additions & 9 deletions maths/aliquot_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,28 @@ def aliquot_sum(input_num: int) -> int:
>>> aliquot_sum(6)
6
>>> aliquot_sum(-1)
ValueError
Traceback (most recent call last):
...
ValueError: Input must be positive
>>> aliquot_sum(0)
ValueError
Traceback (most recent call last):
...
ValueError: Input must be positive
>>> aliquot_sum(1.6)
ValueError
Traceback (most recent call last):
...
ValueError: Input must be an integer
>>> aliquot_sum(12)
16
>>> aliquot_sum(1)
0
>>> aliquot_sum(19)
1
"""
if (not isinstance(input_num, int)) or (input_num <= 0):
raise ValueError
sum = 0
for divisor in range(1, input_num):
if input_num % divisor == 0:
sum += divisor
if not isinstance(input_num, int):
raise ValueError("Input must be an integer")
if input_num <= 0:
raise ValueError("Input must be positive")
return sum(divisor for divisor in range(1, input_num) if input_num % divisor == 0)


Expand Down