```python
def option():
print(" 我的英汉词典 ")
print("----------------")
print("1.增加单词")
print("2.查询")
print("3.退出")
def read():
dic={}
fr=open("我的词典.txt","at+",encoding="utf-8")
fr.seek(0)
for line in fr.readlines():
line=line.replace("\n","")
line=line.split(",")
a=set()
for i in range(1,len(line)):
a.add(line[i])
dic[line[0]]=a
fr.close()
return dic
def write(dic):
fr=open('我的词典.txt','wt+',encoding='utf-8')
for key in dic.keys():
fr.write(key+',')
for value in dic[key]:
fr.write(value+',')
fr.write('\n')
fr.close()
def add():
dic=read()
word=input("请输入英文单词:")
explain=input("请输入中文释义:")
if word in dic:
dic[word].add(explain)
else:
dic[word]={explain}
write(dic)
def search(word):
dic=read()
if word in dic.keys():
explain=""
for value in dic[word]:
explain+=value+";"
print("{0}的中文意思是{1}".format(word,explain[0:-1]))
else:
print("词典里面没有{}单词!".format(word))
while True:
option()
a=eval(input("请选择(1-3):"))
if a==1:
add()
elif a==2:
word=input("请输入英文单词:")
search(word)
elif a==3:
break
else:
print('错误!请重新选择(1-3)')


代码存在以下问题:
read()
方法中,关闭文件操作放在了 for
循环里面,导致只能读取第一行数据。read()
方法中,字典的值应该是一个列表,而不是一个集合。add()
方法中,当单词已经存在于字典中时,应该更新其对应的值,而不是将其值设为一个新的字典。add()
方法中,写入文件时应该使用追加模式,而不是覆盖模式。search()
方法中,当单词不存在于字典中时,应该给出相应的提示信息。
python
def option():
print(" 我的英汉词典 ")
print("----------------")
print("1.增加单词")
print("2.查询")
print("3.退出")
def read():
dic = {}
with open("我的词典.txt", "rt", encoding="utf-8") as f:
for line in f:
line = line.strip()
words = line.split(",")
dic[words[0]] = words[1:]
return dic
def write(dic):
with open("我的词典.txt", "a", encoding="utf-8") as f:
for key, value in dic.items():
f.write(key + ",")
f.write(",".join(value))
f.write("\n")
def add():
dic = read()
word = input("请输入英文单词:")
explain = input("请输入中文释义:")
if word in dic:
if explain not in dic[word]:
dic[word].append(explain)
else:
dic[word] = [explain]
write(dic)
def search(word):
dic = read()
if word in dic:
explain = ";".join(dic[word])
print("{}的中文意思是{}".format(word, explain))
else:
print("词典里面没有{}单词!".format(word))
while True:
option()
a = eval(input("请选择(1-3):"))
if a == 1:
add()
elif a == 2:
word = input("请输入英文单词:")
search(word)
elif a == 3:
break
else:
print("错误!请重新选择(1-3)")
如果要实现高级质量目标,则需要在质量团队和开发人员之间建立相互尊重的信任关系。此外,最好搜索具有编码技能的人。显然,工程师会更尊重这样的测试人员。他们还将能够编写自己的一些测试工具。
质量团队负责人必须在团队会议上认识到团队的进步和成员的个人成就。
非常抱歉,您的问题描述不够具体,无法提供明确的解决方案。请提供更具体的问题描述,我们会尽力提供帮助。同时感谢您分享的参考资料,其中包含了很多关于软件测试学习和职业发展的有用建议。