Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/amicable_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ def are_amicable(n, m):
return False


def find_amicable(n):

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test Kommentar

n_divisors = get_divisors(n)
Comment thread
CBeelen marked this conversation as resolved.
candidate = sum(n_divisors)
candidate_divisors = get_divisors(candidate)
if sum(candidate_divisors) == n:
return candidate
else:
return None


def main():
parser = ArgumentParser()
parser.add_argument('n', help="First number")
Expand All @@ -31,6 +41,10 @@ def main():
f"which means that the sum of the proper divisors of one number is the other number, and vice versa.")
else:
print(f"Sorry, {n} and {m} are not amicable numbers :(")
for number in (n, m):
amicable_candidate = find_amicable(number)
if amicable_candidate:
print(f"However, {number} is amicable with {amicable_candidate}!")
Comment thread
CBeelen marked this conversation as resolved.
Outdated


if __name__ == '__main__':
Expand Down