This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Issue with return in recursive functions
Type: Stage: resolved
Components: Regular Expressions Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, luislopezlazaro, mrabarnett, r.david.murray
Priority: normal Keywords:

Created on 2013-02-25 18:17 by luislopezlazaro, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Chapter 6 MCD Euclidean.py luislopezlazaro, 2013-02-25 18:17 program showing the bug
Messages (3)
msg182966 - (view) Author: Luis López Lázaro (luislopezlazaro) Date: 2013-02-25 18:17
Sorry if I am raising something naive as perhaps I am doing something wrong as I am both an amateur programmer and a newcomer to Python, but version 3.3 appears to have an issue with the return statement in the setting of recursive functions.

When implementing a fruitful recursive function in Python 3.3 (specifically Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32) which depends on conditionals it only returns the result value if the conditions are met in the first iteration.

I am attaching a file in which I have implemented the Euclidean algorithm in 2 slightly different ways. The print statements produce the expected results (for instance with 1000,75) and a print statement placed in the if loop where the return statement is shows the indicator sentence but no value is returned by the function. I have also copied an implementation obtained from a website (function Euclid_LP; obtained from the wiki Literate Programs, http://en.literateprograms.org/Euclidean_algorithm_%28Python%29) and it does not work either.

For the tests, initially I run the program with F5 and invoked the functions from the Python shell. Later I have added a main part of the program prompting for the numbers and calling the functions to later display the results, with no change in the outcome
msg182968 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2013-02-25 18:24
This question should've been posted to python-list@python.org, not here.

Your functions are calling themselves, but not returning the result of the call to their own callers.
msg182972 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-02-25 18:37
Yes, the bug tracker is not a good place to get help on programming.  python-list, or the python-tutors list, will produce much more useful results for you.
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61499
2013-02-25 18:37:01r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg182972

resolution: not a bug
stage: resolved
2013-02-25 18:24:37mrabarnettsetmessages: + msg182968
2013-02-25 18:17:37luislopezlazarocreate