def sumList(arr):
items = len(arr)
if(items == 0):
return 0
elif(items == 1):
return arr[0]
else:
return(arr[0] + sumList(arr[1:]))
print(sumList([2, 4, 6, 10, 123]))
This code will still run if the "else if" part is commented out. But, shouldn't the last else give an error for the last case when only one item is present as it's returning the list starting from index 1, which does not exist?