title: Find the number of characters in a file using Python
body: <p>Here is the question:</p>
  
  <p>I have a file with these words:</p>
  
  <pre><code>hey how are you
  I am fine and you
  Yes I am fine
  </code></pre>
  
  <p>And it is asked to find the number of words, lines and characters.</p>
  
  <p>Below is my program, but the number of counts for the characters without space is not correct.</p>
  
  <p>The number of words is correct and the number of line is correct.
  What is the mistake in the same loop?</p>
  
  <pre><code>fname = input("Enter the name of the file:")
  infile = open(fname, 'r')
  lines = 0
  words = 0
  characters = 0
  for line in infile:
      wordslist = line.split()
      lines = lines + 1
      words = words + len(wordslist)
      characters = characters + len(line)
  print(lines)
  print(words)
  print(characters)
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>lines=3(Correct)
  words=13(correct)
  characters=47
  </code></pre>
  
  <p>I've looked on the site with multiple answers and I am confused because I didn't learn some other functions in Python. How do I correct the code as simple and basic as it is in the loop I've done?</p>
  
  <p>Whereas the number of characters without space is 35 and with space is 45.
  If possible, I want to find the number of characters without space. Even if someone know the loop for the number of characters with space that's fine.</p>