title: adjacent letters in strings
body: <p>Trying to write a program that will calculate the number of matching letter pairs adjacent to one another ("mississippi" contains 3) and output that number.</p>
  
  <p>Not sure what I'm doing wrong, but I have to use strings, a while loop, and variables as parts of the code. It seems to work for the first line and outputs 3, then throws an IndexError: string index out of range for the second string example.</p>
  
  <pre><code>def count_pairs(s):
      index = 0
      pairs = 0
      letter = 0
      nextletter = 0
      while index &lt; len(s):
          letter = s[index]
          index = index + 1
          nextletter = s[index]
          if letter == nextletter:
              pairs = pairs + 1
              index = index + 1
          else:
              index = index + 1
      return pairs
  
  print(count_pairs("ddogccatppig"))
  print(count_pairs("dogcatpig"))
  print(count_pairs("xxyyzz"))
  print(count_pairs("a"))
  </code></pre>