title: How to fix IndexError: string index out of range
body: <p>I'm mostly a Java user, however for my GCSE I have to use Python.
  I was mucking around making an algorithm to find palindromic numbers.
  The code is a big mess, as I .One- haven't yet entirely figured out Python syntax. and .Two- Haven't shortened the algorithm, except making it start from the higher number and work backwards.
  The code is as following for python 3.4.1:</p>
  
  <pre><code>print("This program will find the nearest palindromic number to a given value.")
  countN = input("Input a number above 0 to find the nearest palindromic number")
  countN = str(countN)
  nl = len(countN) # Number length
  pf = 0 # Palindrome found
  while(pf == 0 and int(countN)&gt;=0): #While no palindrome found and count is bigger than 0
   ep = nl # end pointer
  sp = -1 # start pointer
   while(int(ep) &gt;= sp):
  if(int(countN[ep]) == int(countN[sp])):
   ep = ep-1
   sp = sp+1
  print(count + " is a palindrome.")
   pf = 1
  else:
  print(count + " is not a palindrome.")
  countN = countN - 1    
  </code></pre>
  
  <p>I was just thinking the changing the pointers bit, should it be separate from the IF statement?</p>
  
  <p>Anyway the error I am running into is as follows:</p>
  
  <pre><code>&gt;&gt;&gt; 
  This program will find the nearest palindromic number to a given value.
  Input a number above 0 to find the nearest palindroic number99
  Traceback (most recent call last):
    File "C:/Python34/Computer science/palindrome finder.py", line 10, in &lt;module&gt;
      if(int(countN[ep]) == int(countN[sp])):
  IndexError: string index out of range
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>Please note: I have searched here for an answer, part of the reason there are str() and int()'s everywhere.</p>