请写出python程序:1.输入一个英文句子(单词之间用空格分割),统计每个单词出现的次数,并输出
时间: 2024-06-04 09:10:48 浏览: 240
Python统计单词出现的次数
sentence = input("请输入一个英文句子:")
words = sentence.split()
word_counts = {}
for word in words:
if word in word_counts:
word_counts[word] += 1
else:
word_counts[word] = 1
for word, count in word_counts.items():
print(word, "出现了", count, "次")
阅读全文