小明是一名学生,他正在学习英语单词的拼写。他想要创建一个单词表,用于存储他学习过的单词,并统计每个单词出现的次数。请你帮助他补全代码完成以下任务:
word_dict,用于存储单词和对应的出现次数;input() 函数,提示小明输入一个单词,并将其存储到变量 word 中;word_dict 中是否已经存在该单词。如果存在,则将该单词的出现次数加一;如果不存在,则将该单词添加到字典中,并将其出现次数设置为1;s为止;unique_words,用于存储所有不重复的单词;word_dict 的键(即单词),将每个键添加到集合 unique_words 中;word_dict 中每个单词和对应的出现次数;unique_words 中的所有不重复的单词。请输入一个单词:hello
请输入一个单词:world
请输入一个单词:hello
请输入一个单词:python
请输入一个单词:s
单词和出现次数:
hello : 2
world : 1
python : 1
不重复的单词:
world
hello
python
word_dict = {}
while True:
word = input("请输入一个单词:")
if word == "s":
break
if word in word_dict:
①
else:
word_dict[word] = 1
unique_words = ②
for word in word_dict:
unique_words.add(word)
print("单词和出现次数:")
for word in word_dict:
③
print("不重复的单词:")
for word in unique_words:
④