-1

I have this code:

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

If the user looks up a word to find the definition, how would I print the definition from the dictionary?

  • It says how to get the key, but doesn't say how to then print the definition back to the user. I know how to use the dict.get, but whenever I try to print that it doesn't work. – colinpannikkat May 24 '16 at 03:25

1 Answers1

0

You have the definition indexed using the word, so just use the word and get the definition from the dictionary.

if type in words:
print words[type]
else:
Print "not available"
jeffry copps
  • 305
  • 5
  • 22
  • @Choelho The intent was to print the definition for a word contained in the dictionary. Anyways, you had a valid point. (Y) – jeffry copps May 24 '16 at 02:54