def get_divisors(x): divisors = [] for i in range(1,x): if x%i == 0: divisors.append(i) return divisors def get_divisors_sum(x): divisors = get_divisors(x) return sum(divisors) def is_amicable(x): y = get_divisors_sum(x) tmp = get_divisors_sum(y) if x != tmp: print x,"False" return False if x == y: print x,"False" return False print x, y, tmp return [x,y] def get_amicable_list(x): amicable = [] for i in range(x): if (i in amicable): continue tmp = is_amicable(i) if tmp != False: amicable.append(tmp[0]) amicable.append(tmp[1]) return amicable amicable = get_amicable_list(10000) print amicable print sum(amicable)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question