[Tutor] recursion

Alan Gauld alan.gauld at yahoo.co.uk
Mon May 22 17:16:40 EDT 2017


On 22/05/17 17:11, Michael C wrote:

> I have a function to return (x,y) value, but sometimes it would naturally
> unable to return those 2 values properly. I know what recursion is, and I
> think all I got to do is to call this function a 2nd time and the problem
> would go away.

Sorry, but that is too vague to help us in any way.
Recursion is not about calling the function a second time,
it is about calling the function from within the same function.
How or whether that would help solve your problem is not at
all obvious.

You need to ideally show us your code or at least give us more
information about what is going wrong.
What kind of values are you expecting back?
What do you mean by "naturally unable to return those"?
Why not? What does it return instead?
How are the values being returned(or calculated/obtained)?


> How do I do recursion? The function basically look like this
> 
> def return_xy():
>     blah blah blah
>     return x,y

That looks like any function that takes no inputs and returns
a tuple. It does not help us to help you in any way.

The fact that it takes no inputs and does not apparently
modify any state variables means recursion would be pointless
- in fact it would lead to an infinite loop and lock up your
program.

We need more detail, and unless you have a good reason not
to, you should just show us your code. We are ok with you
posting anything up to, say, 100 lines long...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list