title: Getting IndexError: string index out of range in python
body: <p>Getting <strong>IndexError: string index out of range</strong> in python, I'm a beginner in python and trying to make a program that will count total uppercase and lowercase letters and I have also tried some solutions as removing spaces of a string as <code>string.replace(" ", "")</code> but again getting error, </p>
  
  <p><strong>My code</strong></p>
  
  <pre><code>string = input('Enter string upto 25 words: ')
  if len(string) &gt; 25:
    print('Please enter a string less than 25 words.')
  else:
    string.replace(" ", "")
    total_upr = 0
    total_lwr = 0
    i = 0
    while i &lt; 25:
      print(i)
      if string[i].islower():
        total_upr += 1
      elif string[i].isupper():
        total_lwr += 1
      i += 1
    print(f"'{string}' contains {total_lwr} lower-case letters and {total_upr} upper-case letters.")
  </code></pre>