查看单词查找是否等于字典数据,然后打印字典定义

时间:2016-05-24 02:40:01

标签: python dictionary input

我有这段代码:

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 == ??:
   ???

如果用户查找单词以查找定义,我将如何从字典中打印定义?

1 个答案:

答案 0 :(得分:0)

你有使用单词索引的定义,所以只需使用单词并从字典中获取定义。

if type in words:
print words[type]
else:
Print "not available"