fork download
  1. def is_int(e):
  2. return type(e) == int
  3.  
  4. def deep_lst_sum(lst):
  5. total = 0
  6. def helper(lst):
  7. if lst == []:
  8. return 0
  9. elif is_int(lst[0]) == True:
  10. total += lst[0]
  11. return helper(lst[1:])
  12. else:
  13. return helper(lst[0])
  14. helper(lst)
  15. return total
  16.  
  17. deep_lst_sum([6, 2, [8, 4, 5], [9, [5]]])
Runtime error #stdin #stdout #stderr 0.02s 8736KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
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