Here is the problem I am working on:
Return the sum of the numbers in the array, except ignore sections of numbers starting with a 6 and extending to the next 7 (every 6 will be followed by at least one 7). Return 0 for no numbers.
sum67([1, 2, 2])
→ 5sum67([1, 2, 2, 6, 99, 99, 7])
→ 5sum67([1, 1, 6, 7, 2])
→ 4
Here is my solution:
def sum67(nums):
if len(nums) == 0:
return 0
elif 6 not in nums:
return sum(nums)
else:
for num in nums:
if num ==6:
ind_six = nums.index(6)
ind_seven = nums.index(7,ind_six)
del nums[ind_six:ind_seven+1]
else:
pass
return sum(nums)
My code works for all of the listed inputs, but fails "other tests." Please reference the picture. Could anyone help me figure out why? What am I missing? Thank you!! Expected vs run chart
I have tried brainstorming other possible inputs that are failing.