Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Simple recursive sum function | what's the cause of the weird behaviour?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Rotwang, post: 5104040"] I assume you meant to put "result = start" in there at the beginning. It's not quite clear to me what the OP's intentions are in the general case, but calling supersum(item, start) seems odd - for example, is the following desirable? 22 I would have thought that the "correct" answer would be 10. How about the following? def supersum(sequence, start = 0): result = start for item in reversed(sequence): try: result = supersum(item, result) except: result = item + result return result [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Simple recursive sum function | what's the cause of the weird behaviour?
Top