On Tue, Mar 26, 2019 at 5:08 AM Bassam Abdul-Baki <babdulb...@gmail.com> wrote: > > def per(n, steps = 0): > if len(str(result)) == 1: > print(" --- DONE ---") > return "DONE" > else: > per(result, steps) > > ---------- > > What the program does: > If I run per(X) and X is a multiple of 10, I should end up with 0 in a > finite amount of steps. > > The problem: > If I run per(54), I do not get 'DONE' printed through the return > statement. WRONG! > > If I run per(20), I do get 'DONE' printed through the return statement. > CORRECT! > > 20, 30, etc. are correct. 25, 45, etc. are not. > > Is this a bug?
Yes, it is - not a bug in Python, but a bug in the above code :) I would recommend exploring the part of the code that I quoted above, and researching how recursion works, and specifically what 'return' does. That should put you on the right path to figuring this out. ChrisA -- https://mail.python.org/mailman/listinfo/python-list