[Tutor] recursion
hi all: 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. How do I do recursion? The function basically look like this def return_xy(): blah blah blah return x,y ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] recursion
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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] recursion
hi all: oh ya, my function does in fact take no input and doesn't change anything, and all i wanted to was to call itself a 2nd time, yes, so I solved it a few hours back ,and it's good enough for me for now :) Thanks for the response!!! On Mon, May 22, 2017 at 2:16 PM, Alan Gauld via Tutor wrote: > 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 > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] recursion
Michael C wrote: > oh ya, my function does in fact take no input and doesn't change anything, > and all i wanted to was to call itself a 2nd time, yes, so I solved it a > few hours back ,and it's good enough for me for now :) Would you mind showing the code? I'd like to see how you avoid infinite recursion. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor