title: CodingBat sum67: why is this solution wrong?
body: <p>I'm working on the following codingbat problem:</p>
  
  <blockquote>
    <p>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.</p>
  
  <pre><code>sum67([1, 2, 2]) → 5
  sum67([1, 2, 2, 6, 99, 99, 7]) → 5
  sum67([1, 1, 6, 7, 2]) → 4
  </code></pre>
  </blockquote>
  
  <p>My solution is:</p>
  
  <pre><code>def sum67(nums):
      sum = 0 
      throwaway = 0
      for i in range(len(nums)):
          if throwaway == 0:
              if nums[i] == 6:
                  throwaway = 1
          elif throwaway == 1 and i &gt; 0 and nums[i-1] == 7:
              throwaway = 0
          if throwaway == 0:
              sum += nums[i]
      return sum
  </code></pre>
  
  <p>I totally know this is not the best solution, but I'm just curious to know why this is wrong.  Could you please explain me why this is wrong and in which particular case it gives a wrong result?</p>