Python 英文文本单词统计工具 - 查询单词出现次数
'Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. Python is dynamically typed and garbage-collected.'
分割文本并删除逗号和句号
words = text.replace(',', '').replace('.', '').split()
while True: # 接收用户输入 word = input('请输入要查询的单词:')
# 判断是否退出程序
if word == 'quit':
break
# 统计单词出现次数
count = words.count(word)
# 打印结果
print('单词 {} 在文本中出现了 {} 次。'.format(word, count))
原文地址: http://www.cveoy.top/t/topic/miQh 著作权归作者所有。请勿转载和采集!