I've tried to understand the logic and process that causes this, but still don't understand why it's happening. Sorry if it's a really simple/bad question.
This is the question:
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.
This is the code with error:
def sum67(nums):
  ans = 0
  if len(nums) == 0:
    return 0 
  elif 6 not in nums:
    for val in nums:
      ans += val
    return ans  
  elif 6 in nums:
    x = nums.index(6)
    y = nums.index(7, x)
    for i in range(x, y):
      nums.pop(i)
  for val in nums:
    ans += val
  return ans
This is the error:
pop index out of range
 
    