Skip to content

Commit

Permalink
Initial Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket758 committed May 13, 2020
0 parents commit a4c007a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions Interactive Dictionary/data.json

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions Interactive Dictionary/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#import necessary libraries
import json
from difflib import get_close_matches

#load json file
data = json.load(open('data.json'))


# Creating a function to get meaning of the given word from our dictionary
def get_meaning(word):
# Scenario 1: word is in our dictionary
if word in data:
return data[word]
# Scenario 2: There is typo in users input, check for closest matching word
elif len(get_close_matches(word, data.keys(), cutoff=.8)) > 0:
match = get_close_matches(word, data.keys(), cutoff=.8)[0]
check = input("Did you mean %s, instead? Enter Y if yes, otherwise N: " %match)
if check.lower() == 'y':
return data[match]
elif check.lower() == 'n':
return "Word doesn't exist"
else:
return "Invalid choice"
# if word is not not at all available in our vocabulary
else:
return "The Word Doesn't exist in the dictionary, sorry!"

while True:
#get a word from user
word = input('Enter a word you want to know the meaning of: ')
if word == "quit":
break
#print the output
output = get_meaning(word.lower())

# If certain word has more than one meaning then iterate over them
if type(output) == list:
for item in output:
print(item)
else:
print(output)

Binary file added Interactive Dictionary/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a4c007a

Please sign in to comment.