问个问题,这个程序为什么会重复报单词?能不能帮我让它不重复报单词?
代码如下:
import random
u1_words = {"guitar": "n.吉他",
"sing": "v.唱歌",
"swim": "v. & n.游泳",
"dance": "v.跳舞 n.舞蹈",
"draw": "n.画",
"chess": "n.国际象棋",
"play chess": "下国际象棋",
"speak": "v.说(某种语言);说话",
"speak English": "说英语",
"join": "v.参加;加入",
"club": "n.俱乐部;社团",
"be good at ...": "擅长于……",
"tell": "v.讲述,告诉",
"story": "n.故事;小说",
"write": "v.写作;写字",
"show": "n.演出;节目",
"or": "conj.或者;也不(用于否定句)",
"talk": "v. & n.说话,交谈",
"talk to ...": "跟……说",
"kung fu": "n.(中国)功夫",
"drum": "n.鼓",
"play the drums": "敲鼓",
"piano": "n.钢琴",
"play the piano": "弹钢琴",
"violin": "n.小提琴",
"play the violin": "拉小提琴",
"also": "adv.也;而且",
"people": "n.人;人们",
"home": "n.家;活动本部 adv.到家,在家",
"be good with ...": "善于应付……的;对……有办法",
"make": "v.使成为,制造",
"make friends": "结交朋友",
"today": "adv.在今天",
"help (sb.) with sth.": "在某方面帮助(某人)",
"center": "n.中心,中央",
"weekend": "n.周末",
"on the weekend": "(在)周末",
"teach": "v.教;讲授",
"musician": "n.音乐家",
"Lisa": "莉萨(女名)",
"Jill": "吉尔(女名)",
"Peter": "彼得(男名)"}
"""
u2_words至u12_words在此跳过
"""
dictation_words = {}
dictationed_words = []
u1_yesno = input("Unit 1是否可被听写?(y/n)")
if u1_yesno.lower() == "y":
dictation_words.update(u1_words)
u2_yesno = input("Unit 2是否可被听写?(y/n)")
if u2_yesno.lower() == "y":
dictation_words.update(u2_words)
u3_yesno = input("Unit 3是否可被听写?(y/n)")
if u3_yesno.lower() == "y":
dictation_words.update(u3_words)
u4_yesno = input("Unit 4是否可被听写?(y/n)")
if u4_yesno.lower() == "y":
dictation_words.update(u4_words)
u5_yesno = input("Unit 5是否可被听写?(y/n)")
if u5_yesno.lower() == "y":
dictation_words.update(u5_words)
u6_yesno = input("Unit 6是否可被听写?(y/n)")
if u6_yesno.lower() == "y":
dictation_words.update(u6_words)
u7_yesno = input("Unit 7是否可被听写?(y/n)")
if u7_yesno.lower() == "y":
dictation_words.update(u7_words)
u8_yesno = input("Unit 8是否可被听写?(y/n)")
if u8_yesno.lower() == "y":
dictation_words.update(u8_words)
u9_yesno = input("Unit 9是否可被听写?(y/n)")
if u9_yesno.lower() == "y":
dictation_words.update(u9_words)
u10_yesno = input("Unit 10是否可被听写?(y/n)")
if u10_yesno.lower() == "y":
dictation_words.update(u10_words)
u11_yesno = input("Unit 11是否可被听写?(y/n)")
if u11_yesno.lower() == "y":
dictation_words.update(u11_words)
u12_yesno = input("Unit 12是否可被听写?(y/n)")
if u12_yesno.lower() == "y":
dictation_words.update(u12_words)
number = int(input("请输入所报单词个数:"))
for i in range(number):
english = list(dictation_words.keys())
chinese = list(dictation_words.values())
word = random.choice(chinese)
print(word)
en_num = chinese.index(word)
dictationed_words.append(english[en_num])
del english[en_num]
del chinese[en_num]
ok = input("写完请按回车键:")
print()
print("答案如下:")
for j in dictationed_words:
print(j)
帮个忙吧!