forked from larymak/Python-project-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpydictionary.py
More file actions
40 lines (34 loc) · 1.27 KB
/
Copy pathpydictionary.py
File metadata and controls
40 lines (34 loc) · 1.27 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
37
38
39
40
import json
from difflib import SequenceMatcher
from difflib import get_close_matches
# accessing the data.json file
data = json.load(open("076 data.json"))
# function to check if entered word is present in the 076_data.json file and print neccessary output
def translate(w):
if w in data:
return data[w]
elif w.title() in data:
return data[w.title()]
elif w.upper() in data: #in case user enters words like USA or NATO
return data[w.upper()]
elif len(get_close_matches(w,data.keys())) > 0:
answer = input("Did you mean %s instead? enter Y if yes or N if no:"%get_close_matches(w,data.keys())[0])
answer = answer.lower()
if answer == "y" or answer == "yes":
return data[get_close_matches(w,data.keys())[0]]
elif answer == "n" or answer == "no":
return "TRY ANOTHER WORD:"
else:
return "We didn't Understand what you wanted Type y for yes and n for no: "
else:
print ("THE WORD DOESNT EXIST in the data.json database!!!!! ")
word = input("Enter a word:")
word = word.lower()
print(translate(word))
output = translate(word)
#can comment this below not so neccessary.....
if type(output) == list:
for item in output:
print(item)
else:
print (output)