Light Mode
Dark Mode
Recursion error
I would like to give some feedback about ...

From: http://www.checkio.org/mission/restricted-sum/solve/

HTTP\_USER\_AGENT:

    Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36

This is the code I wrote for to return the sum of a list of numbers without using keywords like sum/for/while. Albeit, it's probably pretty sloppy because this is the first time I've tried using recursion, but it keeps failing on checkio([2,2,2,2,2,2]) saying that I returned 14 instead of 12. However, when I've run my code in other consoles (like repl.it and codecademy, it says that it returns 12). Any help or feedback would be awesome! 

My Code:

    added = 0
    counter = 1
    
    def checkio(data):
        global added
        global counter
        finish = len(data)
        added += data[counter-1]
        if counter < finish:
            counter += 1
            checkio(data)
        return added
Created: July 27, 2014, 4:54 p.m.
Updated: July 27, 2014, 9:42 p.m.
0
8
User avatar
thepopil_e339ae396a9e4558af85d