Looking for values in Python Dictionaries
May 19, 2013 in answer
ANSWER:
I got the answer, and it was simple! Here is my revised code:
def sumDivisors(num, divisorSums={}):
if num in divisorSums:
return divisorSums[num]
total = 0
if num == 1:
return 0
for i in xrange(num/2, 0, -1):
if not num % i:
total += i
divisorSums[num] = total
return total
I needed to remove the first conditional statement. Because that would make every value return 1.
Tetramputechture from http://stackoverflow.com/questions/16640738

New Comments