def is_int(e): return type(e) == int def deep_lst_sum(lst): total = 0 def helper(lst): if lst == []: return 0 elif is_int(lst[0]) == True: total += lst[0] return helper(lst[1:]) else: return helper(lst[0]) helper(lst) return total deep_lst_sum([6, 2, [8, 4, 5], [9, [5]]])
Standard input is empty
Standard output is empty
Traceback (most recent call last): File "./prog.py", line 17, in <module> File "./prog.py", line 14, in deep_lst_sum File "./prog.py", line 10, in helper UnboundLocalError: local variable 'total' referenced before assignment
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!