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! James invites him in. The snowman has never been inside a house. He says hello to the cat. He plays with paper towels.A moment later, the snowman takes James’s hand and goes out.They go up up up into the air! They are flying! What a wonderful night!The next morning, James jumps out of bed. He runs to the door.He wants to thank the snowman. But he’s gone.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值