Ad

Write the sum of elements in an array given.

Code
Diff
  • def sumi(arr):
        size = len(arr)
        if size <= 0:
            return 0
        return arr[0] + sumi(arr[1:])
    
    • def sumi(arr):
    • total = 0
    • for value in arr:
    • total += value
    • return total
    • size = len(arr)
    • if size <= 0:
    • return 0
    • return arr[0] + sumi(arr[1:])

The task of this Kumite is to print a string, its length separated by a separator.

Code
Diff
  • print("hello", len("hello"), sep='\n')
    • print("hello", 7, sep='
    • ')
    • print("hello", len("hello"), sep='
    • ')