I am using this program
#Program to find most used word
name = input('Enter a file:') #Ask user for input file,
handle = open(name) #assign a handle to the file name and open file
counts = dict() #make an empty dictionary
for line in handle: #Look at each line
words = line.split() #This splits the line
for word in words: #Look at each word
#If a word exists get the number of words, else default value is zeo
counts[word] = counts.get(word,0) + 1 # +1 is added else default value of found word starts with 0
bigcount = None
bigword = None
for word,count in counts.items(): #Looking at items (items are key and its value)
if bigcount is None or count > bigcount: #If no word is found or if word count is bigger than previous count
bigword = word #Assign new winning word
bigcount = count #Assign new winning count
print (bigword,bigcount) #Print key, value
and I am getting this error when I run it in terminal
[pytest]$ py test.py
Enter a file:sonnets.txt
Traceback (most recent call last):
File "test.py", line 3, in <module>
name = input('Enter a file:') #Ask user for input file,
File "<string>", line 1, in <module>
NameError: name 'sonnets' is not defined
What am I doing wrong here???