-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaryWithSQL.py
More file actions
50 lines (39 loc) · 1.3 KB
/
DictionaryWithSQL.py
File metadata and controls
50 lines (39 loc) · 1.3 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
41
42
43
44
45
46
import mysql.connector
from difflib import get_close_matches
conn = mysql.connector.connect(
user = 'ardit700_student',
password = 'ardit700_student',
host = '108.167.140.122',
database = 'ardit700_pm1database',
connection_timeout=300,
)
cursor = conn.cursor()
cursor.execute("SELECT * FROM Dictionary")
data = dict(cursor.fetchall())
conn.close()
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)