May-19-2024, 12:01 AM
(This post was last modified: May-19-2024, 01:54 AM by deanhystad.)
The code below returns 8. Why does not it return 2 instead? I do not understand how return behaves in the code below. what is the rule? Thanks for your help.. khasbay
def f(x): if x==0: return 2 else: return x+f(x-1) print(f(3))
deanhystad write May-19-2024, 01:54 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.