Dec-13-2017, 12:46 PM
(Dec-13-2017, 10:10 AM)boris602 Wrote: i have changed my code now, i did not know the difference between "print" and "return"︠ def divisorGenerator(n): large_divisors = [] for i in xrange(1, int(math.sqrt(n) + 1)): if n % i == 0: yield i if i*i != n: large_divisors.append(n / i) for divisor in reversed(large_divisors): yield divisor def sumdivisorGenerator(n): return sum (list(divisorGenerator(n))) def catalansequence(n): return (sumdivisorGenerator(n)-n) def length(n): if sumdivisorGenerator(n)==0: return 0Now i need to define my length (n). If sumdivisorGenerator(0) the result=0. But now i need this procedure to break if a number gets hit twice or put out the length(n). I would be really grateful for some hint.
I don't quite understand what length(n) is supposed to output. Is it the number of times sumdivisorGenerator is called? Is it the length of the list you created in sumdivisorGenerator? I assume it's this, that length(n) should output the number of numbers that can divide n.
Python includes a length function, called len https://docs.python.org/3.6/library/functions.html#len that operates on lists just like the sum function does.