title: String index out of range in Python
body: <pre><code>def romanToNum(word):
      word = word.upper()
  
      numeralList2 = list(zip(
          [1000, 500, 100, 50, 10, 5, 1],
          ['M', 'D', 'C', 'L', 'X', 'V', 'I']
      ))
      num = 0
      x = []
      a = 0
      b = 2
  
  
      if len(word) % 2 != 0:
          word = word + "s"
  
      for i in range(0,len(word)):
          x.append(word[a:b])
          a = a + 2
          b = b + 2
          print(x[i]) 
  
      for n in x:
          for nNum,rNum in numeralList2:
              if n == rNum:
                  num = nNum + num 
              elif n == (n[0] + n[1]):
                  num = (nNum*2) + num             
              elif n[0] == rNum:
                  r1 = 0
                  r1 = nNum
              elif n[1] == rNum:
                  r2 = 0
                  r2 = nNum
              elif r1 &lt; r2:
                  num = num + (r2 - r1)
              elif r1 &gt; r2:
                  num = num + (r1 + r2)            
      return num        
  
  romanToNum("xxx")
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <pre><code>  elif n == (n[0] + n[1]):
  IndexError: string index out of range
  </code></pre>
  
  <p>and it doesn't matter where I put that in the loop, it just wont recognize that <code>n</code> has an index value. </p>
  
  <p>I also get this error: <code>Traceback (most recent call last):</code> </p>
  
  <p>which points to when i call my function: <code>romanToNum("xxx")</code></p>
  
  <p>I'm not really sure what's going on because I added a <code>print</code> statement to where I'm appending my list and there <strong>is</strong> an index of <strong>at least <code>[0]</code></strong> when I print it all out. Any help here?</p>
  
  <p>I have looked through stack for similar questions but the solution for them is an indentation or because they had a negative index( <code>[-1]</code> ) or something along those lines but all my indentation is correct and my index's are all positive.  </p>