Before I get hate, I haven't found a link which answers my question. I am a beginner at Python 3.
I am supposed to write a function to open a file I wrote (data.txt) which says 'Hi there!' with a newline character that is suppose to give me a count of 10.
The code I have written below gives me the first test case value of 10 but it fails the hidden test case - which is supposed to give me a value of 81. What is wrong with my code?
def file_size(lines):
"""docstring"""
with open('data.txt', 'r') as file:
lines = file.read()
return len(lines)
print(file_size('data.txt'))
# data.txt contains 'Hi there!' followed by a new line character.
ans = file_size('alongertextfile.txt')
print(ans)