I have a list of numbers , and I want to add up the numbers, but I don't want to add all the numbers from the list, just the selected numbers, like the first three.
list = [2, 3, 7, 11, 15, 21]
for i in list:
sum += i
My code obviously adds up all the numbers from the list. I've tried changing the for loop to in range(0,4) but that just added together numbers 0, 1, 2, 3 and not the numbers from my list. So how can I modify my code to add up the first three numbers from my list.