-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject1.py
More file actions
32 lines (26 loc) · 981 Bytes
/
project1.py
File metadata and controls
32 lines (26 loc) · 981 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 # importing libraries
from difflib import get_close_matches
data = json.load(open("data.json")) ##loading python into data type
def translate(w): # need 3 conditionals
w = w.lower()
if w in data:
return data[w]
elif w.title() in data:
return data[w.title()] # print Texas instead of texas
elif len(get_close_matches(w, data.keys())) > 0:
yn = input("Did you mean %s instead? Enter Y if yes, or N if no. " % get_close_matches(w, data.keys())[0])
if yn == "Y":
return data[get_close_matches(w, data.keys())[0]]
elif yn == "N":
return "This word does not exist. Please double check it."
else:
return "We didn't understand your entry."
else:
return "This word does not exist. Please double check it."
word = input("Enter a Word: ")
output = translate(word)
if type(output) == list:
for item in output:
print(item)
else:
print(output)