Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Amicable numbers.
#1
I want to create a program, which will find pairs of amicable numbers lower than n.
I wrote a cod :
def sumdiv(n):
    Sum = 0
    for x in range(1, n // 2 + 1):
        if n % x == 0:
            Sum += x
    return Sum

def amicable(n):
    for x in range(1, n):
        if sumdiv(sumadiv(x)) == x and sumdiv(x) != x:
            print(x, "and", sumdiv(x), "are amicable")



m=int(input("Any natural number:"))
print(amicable(m))
I have problem, because I don't know why I get double pairs, for example (220,284) and (284,220).
Reply


Messages In This Thread
Amicable numbers. - by pawlo392 - Mar-21-2019, 09:20 PM
RE: Amicable numbers. - by nilamo - Mar-21-2019, 09:28 PM
RE: Amicable numbers. - by pawlo392 - Mar-21-2019, 09:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,519 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  Convert list of numbers to string of numbers kam_uk 5 3,128 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Regular Expressions in Files (find all phone numbers and credit card numbers) Amirsalar 2 4,186 Dec-05-2017, 09:48 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020