hi, i was given a code to count the words in a paragraph, but i keep getting "NameError: name 'mobypara' is not defined" every time i run it (mobypara is the name of the paragraph).
i made sure the code and the paragraph are both saved in the same file, but that didn't change anything.
here is the code:
that's my input:
countWords(mobypara.txt)
and that's the output:
Traceback (most recent call last):
File "<ipython-input-3-2217261c2031>", line 1, in <module>
countWords(mobypara.txt)
NameError: name 'mobypara' is not defined
any idea what's wrong?
thanks
nadi
i made sure the code and the paragraph are both saved in the same file, but that didn't change anything.
here is the code:
1 2 3 4 5 6 7 8 9 10 11 |
def countWords(filename): counts = {} inf = open (filename, 'r' ) for line in inf: words = line.split() for word in words: if word in counts: counts[word] + = 1 else : counts[word] = 1 return counts |
countWords(mobypara.txt)
and that's the output:
Traceback (most recent call last):
File "<ipython-input-3-2217261c2031>", line 1, in <module>
countWords(mobypara.txt)
NameError: name 'mobypara' is not defined
any idea what's wrong?
thanks
nadi