[Tutor] Re:-Recursive Functions (fwd)

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon Jun 2 01:36:02 2003


Hi everyone,

Evirpides just sent me this message a few minutes ago. I feel terrible for
being hard on him on my last message, in light that that he just sent
this.  But why did he send the replies in two separate messages?

Evripides, my apologies for misjudging you.  Can someone else handle this
for the moment, though?  I need some personal time to recharge.  Thanks.



---------- Forwarded message ----------
Date: Mon, 02 Jun 2003 05:06:56 +0000
From: Evripides Loizides <loizie@hotmail.com>
To: dyoo@hkn.eecs.berkeley.edu
Subject: Re: [Tutor] Re:-Recursive Functions


on code with recursion is this:

def nLines(n):
    if n>0:
        print "hi"
        nLines(n-1)
nLines(5)

prints hi in n lines here we give number n ==5

another one is the countdown:

def countDown(n):
    if n == 0:
        print "hi"
    else:
        print n
        countDown(n-1)
countDown(5)


>>>
5
4
3
2
1
hi


>From: Danny Yoo
>To: Evripides Loizides
>CC: tutor@python.org
>Subject: Re: [Tutor] Re:-Recursive Functions
>Date: Sun, 1 Jun 2003 20:23:09 -0700 (PDT)
>
> > i got taht right too but using while loop if u ask me to do it again
> > using recursive function i will not be able.
>
>Hi Evripides,
>
>Ok, I'm now not so certain that we're using the same definition for the
>word "recursive", and that worries me. Well, to tell the truth, I'm
>actually a little frustrated with myself, because I'm not quite sure why
>we are miscommunicating. We have to get at the bottom of this.
>
>
> > # we have the word house we can find the last character like taht:
> > word = "house"
> > length = len(word)
> > lastLetter = word[length - 1]
> > print lastLetter
>
>This is nice... but this really has nothing to do with what we talked
>about in our last message. Well, it does use the len() function, but
>that's really way off tangent.
>
>
>The question I asked last message was to see if you could try writing a
>function that would do the work that the len() function does.
>Specifically: there's a difference between using len() and implementing
>len(), and I wanted to see how you'd implement len(). But that didn't
>work; you ignored that part of the message.
>
>
>Ok, let's try something else. A while back, you said:
>
> > i understand what a recursive function does. the problem im facing is
to
> > apply it on my problem here what i have right now and let me know if
i
> > am in the rigth direction ok
>
>Out of the risk of being bluntly rude, I need to ask for reassurrance.
>Can you show us a particular example of a recursive function that you've
>seen before? In your own words, what does a recursive function do?
>
>Show us what you think a "recursive" defintion means. And not just
>abstract definitions: show us a concrete example of a recursive function
>that you've seen.
>
>You have to understand, we cannot read your mind. We need some kind of
>background on what you know --- we won't treat you as a sponge or a
blank
>slate. From what you've written, we have a pretty good idea that you
know
>about loops and how to do variable assignments. That's a good start: now
>show us more about what you mean when you say "recursion".
>

________________________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.