Hello everyone! I have created a program that is supposed to read files. All the codes are correct, but I'm just getting an error that it can't find a file. I create a simple txt file using notepad and saving it. I am still getting errors it cant find it but I know its there. Can someone help me? Thanks!
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)
THIS IS THE ERROR IM GETTING WHEN RUNNING IT BELOW:
Enter the name of the file:lamb
Traceback (most recent call last):
File "C:\Users\Bryan\AppData\Local\Programs\Python\Python38\HW extra credit #1.py", line 2, in <module>
infile = open(fname, "r")
FileNotFoundError: [Errno 2] No such file or directory: 'lamb'
>>>
RESTART: C:\Users\Bryan\AppData\Local\Programs\Python\Python38\HW extra credit #1.py
Enter the name of the file:lamb.txt
Traceback (most recent call last):
File "C:\Users\Bryan\AppData\Local\Programs\Python\Python38\HW extra credit #1.py", line 2, in <module>
infile = open(fname, "r")
FileNotFoundError: [Errno 2] No such file or directory: 'lamb.txt'