title: Python: Maximum recursion depth while getting the str of an object
body: <p>I'm making a program to get the amount of letters in a number:</p>
  
  <pre><code>def convert(number):
      lettercount = 0
  
      numstr = str(number)
  
      # One's places
      if len(numstr) is 1:
          if number == 1 or number == 2 or number == 6:
              lettercount += 3
  
          elif number == 4 or number == 5 or number == 9:
              lettercount += 4
  
          else:
              lettercount += 5
  
      # Ten's places
      elif len(numstr) is 2:
          if number == 10:
              lettercount += 3
  
          elif number == 11 or number == 12:
              lettercount += 6
  
          elif number == 15 or number == 16:
              lettercount += 7
  
          elif number == 13 or number == 14 or number == 19:
              lettercount += 8
  
          elif number == 17 or number == 18:
              lettercount += 9
  
          elif number == 20 or number == 30 or number == 40 or\
              number == 80 or number == 90:
              lettercount += 6
  
          else:
              lettercount += convert(int((numstr)[-1]))
              lettercount += convert(int(round(number, -1)))
  
      return lettercount
  
  print "88 has %i letters in its name." % convert(88)
  print "23 has %i letters in its name." % convert(23)
  print "46 has %i letters in its name." % convert(46)
  </code></pre>
  
  <p>It works just fine and returns a correct response for the 88 and 23, but it gives a recursion depth error on 46. I'm confused; why does it happen on just 46? </p>
  
  <hr>
  
  <p>Fixed code: </p>
  
  <pre><code>def convert(number):
      lettercount = 0
  
      numstr = str(number)
  
      # One's places
      if len(numstr) == 1:
          if number == 1 or number == 2 or number == 6:
              lettercount += 3
  
          elif number == 4 or number == 5 or number == 9:
              lettercount += 4
  
          else:
              lettercount += 5
  
      # Ten's places
      elif len(numstr) == 2:
          if number == 10:
              lettercount += 3
  
          elif number == 40 or number == 50:
              lettercount += 5
  
          elif number == 11 or number == 12 or number == 20 or number == 30 or\
              number == 80 or number == 90:
              lettercount += 6
  
          elif number == 15 or number == 16:
              lettercount += 7
  
          elif number == 13 or number == 14 or number == 19:
              lettercount += 8
  
          elif number == 17 or number == 18:
              lettercount += 9
  
          else:
              lettercount += convert(int((numstr)[-1]))
              lettercount += convert((int(numstr) // 10) * 10)
  
      return lettercount
  
  print "88 has %i letters in its name." % convert(88)
  print "23 has %i letters in its name." % convert(23)
  print "46 has %i letters in its name." % convert(46)
  </code></pre>