这是迄今为止我所知道的,但是我的pparagraph只包含5个句号,因此只有5个句子。但它一直保持返回14作为答案。谁能帮忙?如何计算python中段落中句子的数量
file = open ('words.txt', 'r')
lines= list (file)
file_contents = file.read()
print(lines)
file.close()
words_all = 0
for line in lines:
words_all = words_all + len(line.split())
print ('Total words: ', words_all)
full_stops = 0
for stop in lines:
full_stops = full_stops + len(stop.split('.'))
print ('total stops: ', full_stops)
这里是txt文件
车床是根据规则的表上的磁带 的条操纵符号的装置。尽管简单,但图灵机可以适用于模拟任何计算机算法的逻辑,特别是用于解释计算机内部CPU的功能的 。 1933年,Alan Turing对“图灵”机器进行了描述,他称之为“一种(自动)机器”。图灵机并不是作为一种实用的计算技术,而是作为代表计算机的虚拟设备。图灵机帮助计算机科学家理解机械计算的极限。
您正在计算零件*之间*满座。为什么不使用'stop.count('。')'而不是? – 2013-03-05 15:46:18
你可以发布words.txt内容吗? – drekyn 2013-03-05 15:46:22
@MartijnPieters不仅是时段之间的分段,还有换行符和句点之间的分段。 – 2013-03-05 15:47:24