I'm new here, but I hope I can get some help. The problem is this:
SUMMER OF '69: Return the sum of the numbers in the array, except ignore sections of numbers starting with a 6 and extending to the next 9 (every 6 will be followed by at least one 9). Return 0 for no numbers.
summer_69([1, 3, 5]) --> 9
summer_69([4, 5, 6, 7, 8, 9]) --> 9
summer_69([2, 1, 6, 9, 11]) --> 14
I saw an answer in the forum that seems simple:
def summer_69(arr):
if 6 and 9 in arr:
c=sum(arr[arr.index(6):arr.index(9)+1)
return sum(arr)-c
else:
return sum(arr)
It works, but I didn't understand why do I have to add 1 to the index sum. Can someone clarify this to me?