Slice and sum



Problem to sum the less than k index value.



Example-1:


Input    : n = [ 1, 3, 5, 7]  k = 2
Output   : 4  


Example-2:


Input    : n = [ 1, 2, 3, 4, 5]  k = 3 
Output   : 6   







Solution




n = [ 1, 3, 5, 7]

k = 2

a = sum(n[:k])

print(a)



Output



4