Skip to content

Commit

Permalink
Merge pull request #1 from fredcodee/fredcodee-python-dictionary-1
Browse files Browse the repository at this point in the history
dictionary app added to python projects
  • Loading branch information
fredcodee authored Oct 3, 2020
2 parents 5ea004e + 1003ad3 commit 8d9d179
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions Projects/Python/terminal dictionary app/076 data.json

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions Projects/Python/terminal dictionary app/dictionary.py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import json
#python module that compares sequence
from difflib import get_close_matches

#json file
dic_data = json.load(open("076 data.json"))
user_word = input("Search for a word: ")


def translate(word):
if word.title() in dic_data:
definition = "\n".join(dic_data[word.title()])
return definition
elif word.upper() in dic_data:
definition = "\n".join(dic_data[word.upper()])
return definition
elif word.lower() in dic_data:
definition = "\n".join(dic_data[word.lower()])
return definition
elif len(get_close_matches(word,dic_data.keys())) > 0:
#comparing the word provided with the keywords in json data
close_match = get_close_matches(word,dic_data.keys())[0]
user = input("did you mean %s instead yes or no: " % close_match)
if user == "yes":
return("\n".join(dic_data[close_match]))
elif user == "no":
return("the word does not exist")
else:
return("please check your entry")
else:
return("word not found!!!, please check your word")

print(translate(user_word))

0 comments on commit 8d9d179

Please sign in to comment.