I am trying to write a function that counts the number of characters in a text file and returns the result. I have the following code;
def file_size(filename):
"""Function that counts the number of characters in a file"""
filename = "data.txt"
with open(filename, 'r') as file:
text = file.read()
len_chars = sum(len(word) for word in text)
return len_chars
This seemed to be working fine in my IDE when I test ran it with a text file that I created. However when I submit the code to a doctest program I get an error saying it always gives the output of 10. Any help?
Attached is a screenshot of the error message Error screen.