Python Forum
recursive procedure(total beginner)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
recursive procedure(total beginner)
#4
(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 0
    
Now 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.
Reply


Messages In This Thread
recursive procedure(total beginner) - by boris602 - Dec-12-2017, 02:29 PM
RE: recursive procedure(total beginner) - by mpd - Dec-12-2017, 03:29 PM
RE: recursive procedure(total beginner) - by mpd - Dec-13-2017, 12:46 PM
RE: recursive procedure(total beginner) - by mpd - Dec-13-2017, 01:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating Disassembler for a bin file(total beginner) SoulsKeeper 1 2,593 Sep-04-2018, 04:15 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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