import string
def wordcount(text):
# 去掉标点符号并转换为小写
text = text.translate(str.maketrans('', '', string.punctuation)).lower()
# 按空格分割文本
words = text.split()
# 统计单词出现次数
word_count = {}
for word in words:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
return word_count
# 测试
text = """Hello world!
This is an example.
Word count is fun.
Is it fun to count words?
Yes, it is fun!"""
result = wordcount(text)
print(result)