Menu Driven Dictionary Program – Python Lab Program

import json
from difflib import get_close_matches
data=json.load(open("mean.json"))
def translate(w):
    w=w.lower()
    if w in data:
          return data[w]
    elif len(get_close_matches(w,data.keys())) > 0:
          yn=input("Did you mean %s instead? Enter Y if yes, or N if no:" %
get_close_matches(w, data.keys())[0])
         yn=yn.lower()
         if yn=="y":
                 return data[get_close_matches(w,data.keys())[0]]
         elif yn=="n":
                 return "The word does'nt exist. Please double click it"
         else:
                  return "We didn't understand your entry"
    else:
          return "The word doesn't exist. Please check it"
#Driver Code
word=input("Enter word: ")
output=translate(word)
if type(output)==list:
      for item in output:
           print(item)
else:
      print(output)
input('Press Enter to exit')
{
"appeal": "a request to the public for money, information, or help",
"appropriate": "suitable or right for a particular situation or occasion",
"blameless": "not responsible for anything bad",
"contribute": "to give something, especially money, in order to provide or
achieve something together with other people",
"combine": "to (cause to) exist together, or join together to make a single thing
or group",
"impact": "the force or action of one object hitting another",
"initiative": "a new plan or process to achieve something or solve a problem"
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.