-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp1.1.py
53 lines (37 loc) · 1.35 KB
/
app1.1.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
from difflib import get_close_matches
data = json.load(open("data.json"))
def output(results):
if type(results) == list :
for item in results:
print(item)
else :
print(results)
def meaning(word):
word=word.lower()
if word in data:
return data[word]
elif word.capitalize() in data:
return data[word.capitalize()]
elif word.upper() in data:
return data[word.upper()]
elif len(get_close_matches(word,data.keys(),n=1,cutoff=0.8))>0:
response = input("Did you mean %s instead ? Enter Y for yes and N for no : " % get_close_matches(word,data.keys(),n=1,cutoff=0.7)[0])
if response=="Y" or response=="y" :
return data[get_close_matches(word,data.keys(),n=1,cutoff=0.8)[0]]
elif response=="N" or response=="n" :
word = input("Enter new word : ")
outputs = meaning(word)
show = output(outputs)
return
else:
return "Invalid input . "
else :
return "Word dose not exist. Please check the word again."
word = input("Enter word: ")
if word == "" :
print("No input recived.")
word = input("Enter word again : ")
outputs=meaning(word)
show = output(outputs)
close = input("Press any key to exit : ")