title: CodingBat Python - List 2 sum(67)
body: <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>
  
  <p>Kindly Help me with the solution. For other input values i am getting correct output value.. and also suggest me a short way to write the code.. It seems bit too long</p>
  
  <pre><code>def sum67(nums):
    count=0
    i=0
    switch = 0
    if len(nums) == 0:
      count=0
    else:
      while i &lt; len(nums):
        if nums[i] != 6 and switch == 0 and nums[i] != 7:
          count += nums[i]
          i+=1
          #print("incremented")
          continue
        if nums[i] == 6 and switch == 0:
          switch = 1
          #print("switch ON")
          i+=1
        if nums[i] == 6 and switch == 1:
          i+=1
        if nums[i]==7 and switch==0 :
          count+=nums[i]
          #print("again 7")
          i+=1
        if switch == 1 and nums[i] == 7:
          switch = 0
          #print("switch OFF")
          i+=1
        else:
          i+=1
    #print(count)
    return count
  </code></pre>
  
  <p>OUTPUT :
  Input 1 : sum67([2, 7, 6, 2, 6, 7, 2, 7]) 
  expected :18<br>
  output I got :20    </p>
  
  <p>Input 2 : sum67([2, 7, 6, 2, 6, 2, 7])
  expected : 9
  Output I got : 11</p>