0004题--任一个英文的纯文本文件,统计其中的单词出现的个数.
今天练习了一个简单的项目,后面有我自己在网上找的一段文章用作练习。 0004题–任一个英文的纯文本文件,统计其中的单词出现的个数. import sys x=input("请输入你查找的单词") txt1=open(r'D:\python练习内容\learning1.txt') txt2=txt1.read() txt_list=txt2.split(' ') a=0 i=0 for i in range(len(txt_list)): if txt_list[i] == x: a += 1 print(x,"在文章中出现的次数为:") print(a) 我所使用的文章是这一段: Hooray! It’s snowing! It’s time to make a snowman.James runs out. He makes a big pile of snow. He puts a big snowball on top. He adds a scarf and a hat. He adds an orange for the nose. He adds coal for the eyes and buttons.In the evening, James opens the door. What does he see? The snowman is moving!