-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaryWithJSON.py
More file actions
39 lines (29 loc) · 1.02 KB
/
Copy pathDictionaryWithJSON.py
File metadata and controls
39 lines (29 loc) · 1.02 KB
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
33
34
35
36
import json
from difflib import get_close_matches
data = json.load(open("data.json"))
def translate(user_input):
user_input = user_input.lower()
if user_input in data:
return data[user_input]
elif user_input.title() in data:
return data[user_input.title()]
elif user_input.upper() in data:
return data[user_input.upper()]
elif len(get_close_matches(user_input, data.keys())) > 0:
close_match = get_close_matches(user_input, data.keys())[0]
choice = input("Did you mean %s instead? Enter Y if yes, or N if no." % close_match)
if choice == "Y":
return data[close_match]
elif choice == "N":
return "The word doesn't exit! Please Enter a valid word!"
else:
return "We didn't understand you entry."
else:
return "The word doesn't exit! Please Enter a valid word!"
word = input("Enter word: ")
output = translate(word)
if type(output) == list:
for item in output:
print(item)
else:
print(output)