책 내용에 대한 무단배포 방지를 위해 최소한으로 정리
def countWord(filename, word):
with open(fielname, 'r') as f:
text = f.read()
text = text.lower()
pos = text.fine(word)
count = 0
while pos != -1:
count += 1
post = text.find(word, pos+1)
return count
word = input('mydaata.txt에서 개수를 구할 단어를 입력하세요:')
word = word.lower()
ret = countWord('mydata.txt', word)
print(f'[{word}]의 개수: {ret})
Comments