python单词统计、给定一个段落()_计算段落中的句子数

嗨,我在这里读了所有关于计算句子和单词的主题,我不想打开任何文件,我只想计算字符串中单词和句子的数量。我已经完成了字数统计,我很高兴,我只是不知道从这里该怎么办。以下是我目前所掌握的情况。在import re

line = (" A Turing machine is a device that manipulates "

"symbols on a strip of tape according to a table "

"of rules. Despite its simplicity, a Turing machine "

"can be adapted to simulate the logic of any computer "

"algorithm, and is particularly useful in explaining "

"the functions of a CPU inside a computer. The 'Turing'"

" machine was described by Alan Turing in 1936, who "

"called it an""a(utomatic)-machine"". The Turing "

"machine is not intended as a practical computing "

"technology, but rather as a hypothetical device "

"representing a computing machine. Turing machines "

"help computer scientists understandthe limits of "

"mechanical computation.")

print (line)

print ()

count = len(re.findall(r'\w+', line))

print ("The number of words in this paragraph:", count)

单词计数出来是98,这是完美的,我知道这一段有错误,但他们是故意的,所以我知道它的工作是正确的。我现在想数数句子的数量,应该是5,但我不知道怎么计算。任何帮助都将不胜感激。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值