When I execute the code down below in the Sublime text editor, the input() doesn’t work. I mean when I input a text and press the enter button, it doesn’t execute the code, rather it just goes to the next line.
Can someone tell me what the problem is?
# counting the words in a file and finding the most frequent word
name = input('Enter file: ')
handle = open(name)
counts = dict()
for line in handle:
words = line.split()
for word in words:
counts[word] = counts.get(word, 0) + 1
bigcount = None
bigword = None
for word,count in counts.items():
if bigcount is None or count > bigcount:
bigword = word
bigcount = count
print(bigword, bigcount)
It just prints the input text Enter file: . But when I type something as an input and press the enter button, instead of executing the next codes it just goes to the next line in output panel.
I think it’s because it’s in the Sublime text editor. I ran the code in VS Code and it gave the right output - the most frequent word and the number of times it occurred.