How can I write a function to get the sum of the items in the given list between the indices a and b. For example give aList=[6,3,4,2,5]
and a=1
, b=3
, the function should return 9. Here is my code:
def sumRange(L,a,b):
sum= []
L = [6,3,4,2,5]
for i in range(a,b+1,1):
sum +=L[i]
return sum