def compute(arr, size):
if not arr:
return size
else:
compute(arr[1:], size+1)
def count(sequence):
result = compute(sequence, 0)
return result
array = [i for i in range(1, 101)]
print(count(array))
- I am trying to build my own custom method of count
My intention is not to reinvent the wheel but to understand better about recursion and iteration
- I have a compute a compute method that slices the array in every call and increments the size variable. When the array becomes empty , it returns the size.
but I am getting the result as None
. Please let me know if I am doing something wrong here