def wordcount(text):
# 创建一个空字典来存储单词计数
counts = {}
# 将文本转换为小写,去除标点符号,然后按空格分割成单词
words = text.lower().replace('.', '').replace(',', '').split()
# 遍历所有单词进行计数
for word in words:
if word in counts:
counts[word] += 1
else:
counts[word] = 1
return counts
# 示例文本
text = "Hello world! "
# 调用 wordcount 函数并打印结果
print(wordcount(text))
任务二
使用本地vscode连接远程开发机