Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def countWord(text,word):
- count = int()
- words = text.split()
- for each in words:
- if each == word:
- count += 1
- return count
- filename = input("Enter file to analyze: ")
- char = input("What word do you want to count?: ")
- with open(filename, 'r') as fi:
- text = fi.read()
- print(countWord(text,char))
Add Comment
Please, Sign In to add comment