我有这段代码:
while True:
words = {}
aorl = raw_input("Add or look up a word (a/l)? ")
if aorl == "a":
word = raw_input("Type the word: ")
definition = raw_input("Type the definition: ")
words[word] = str(definition)
print "Word added!"
elif aorl == "l":
type = raw_input("Type the word: ")
if type == ??:
???
如果用户查找单词以查找定义,我将如何从字典中打印定义?
答案 0 :(得分:0)
你有使用单词索引的定义,所以只需使用单词并从字典中获取定义。
if type in words:
print words[type]
else:
Print "not available"