-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
32 lines (28 loc) · 959 Bytes
/
dictionary.py
File metadata and controls
32 lines (28 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import json
from difflib import get_close_matches
data = json.load(open("data.json"))
def translate(word):
if word in data:
return data[word]
elif word.title() in data:
return data[word.title()]
elif word.upper() in data:
return data[word.upper()]
elif len(get_close_matches(word, data.keys())) > 0:
yn = input("Did you mean %s, Enter Y if yes and N if No " % get_close_matches(word, data.keys())[0])
if yn == "Y":
return data[get_close_matches(word, data.keys())[0]]
elif yn == "N":
return "Restart the program and enter the right word"
else:
return "your entry is invalid, please try again"
else:
return "This word is not in the dictionary, try again."
word = input("Enter word: ")
word = word.casefold()
defination = translate(word)
if type(defination) == list:
for i in defination:
print(i)
else:
print(defination)