1

Question was answered and worked.

2 Answers2

1

The file.readline method always returns a string with a trailing newline character (unless it's at the end of file and the file does not end with a newline character), so you should use the str.rstrip method to remove the trailing newline character before processing the string:

line1 = f.readline().rstrip('\n')
blhsing
  • 77,832
  • 6
  • 59
  • 90
0
f.readline()

Reads each line in the file, including empty lines, for which it will just return the linebacker ('\n'). Usually you don't see it because print() handles it automatically, but your function counts this as a separate character. See if you have any empty lines at the end of your file, and just backspace them and save. Hope this helps.

Petru Tanas
  • 861
  • 1
  • 9
  • 31