用python输入一个包含标点符号的英文句子,统计输出句子中单词个数
时间: 2024-05-07 18:16:26 浏览: 248
Python实现统计单词出现的个数
Sure, I can help you with that! Here's some Python code to count the number of words in an English sentence with punctuation:
```
import re
sentence = input("Please enter an English sentence: ")
# Remove all punctuation from the sentence
sentence = re.sub(r'[^\w\s]', '', sentence)
# Split the sentence into words and count the number of words
word_count = len(sentence.split())
print("The number of words in the sentence is:", word_count)
```
Let me know if you have any other questions!
阅读全文