Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dictionary app added to python projects #1

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))