Olegos

Sum massive

May 28th, 2022 (edited)
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. inp_data = [1, 2, 3, 4]
  2.  
  3. def summ(cou):
  4.      _ = 0
  5.      for i in range(len(cou)): _ += cou[i]
  6.      return _
  7. print(summ(inp_data))
  8.  
  9. def summ_re(list_, summ=0, index=0):
  10.     if index < len(list_):
  11.        return summ_re(list_, summ+list_[index], index + 1)
  12.     else:
  13.         return summ
  14. print(summ_re(inp_data))
  15.  
  16. def summ_wh(list_):
  17.     summ = 0
  18.     index = 0
  19.     while index < len(list_):
  20.         summ += list_[index]
  21.         index += 1
  22.     return summ
  23. print(summ_wh(inp_data))
Add Comment
Please, Sign In to add comment