title: Python word counting program for .txt files keeps on showing string index out of range as an error code
body: <p>Im pretty new to this and i was trying to write a program which counts the words in txt files. There is probably a better way of doing this, but this was the idea i came up with, so i wanted to go through with it. I just don´t understand, why i, or any variable, does´nt work for as an index for the string of the page, that i´m counting on...
  Do you guys have a solution or should i just take a different approach?</p>
  <pre><code>page = open(&quot;venv\harrry_potter.txt&quot;, &quot;r&quot;)
  alphabet = &quot;qwertzuiopüasdfghjklöäyxcvbnmßQWERTZUIOPÜASDFGHJKLÖÄYXCVBNM&quot;
  
  # Counting the characters
  
  list_of_lines = page.readlines()
  characternum = 0
  textstr = &quot;&quot;    # to convert the .txt file to string
  
  for line in list_of_lines:
      for character in line:
          characternum += 1
          textstr += character
  
  # Counting the words
  
  i = 0
  wordnum = 1
  
  while i &lt;= characternum: 
      if textstr[i] not in alphabet and textstr[i+1] in alphabet:
          wordnum += 1
      i += 1
  
  
  print(wordnum)
  
  page.close()
  </code></pre>
  <p>Counting the characters and converting the .txt file to string is done a bit weird, because i thought the other way could be the source of the problem...
  Can you help me please?</p>