嗨,我在这里读了所有关于计算句子和单词的主题,我不想打开任何文件,我只想计算字符串中单词和句子的数量。我已经完成了字数统计,我很高兴,我只是不知道从这里该怎么办。以下是我目前所掌握的情况。在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,但我不知道怎么计算。任何帮助都将不胜感激。在