-
Notifications
You must be signed in to change notification settings - Fork 385
/
Copy pathdictionary.py
74 lines (55 loc) · 2.07 KB
/
dictionary.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from PyDictionary import PyDictionary
dictionary = PyDictionary()
def check_meaning(word): # if user want to check meaning of word
return dictionary.meaning(word)
def get_antonym(word): # if user want to check antonym of word
return dictionary.antonym(word)
def get_synonym(word): # if user want to check synonym of word
return dictionary.synonym(word)
def translate(word,language): # if user want to translate word into other language
return dictionary.translate(word,language)
def menu():
print('''
----------------------------------------------
Enter 1 to check meaning of word
Enter 2 to get antonyms of word
Enter 3 to get synonyms of word
Enter 4 to translate word to other language
Enter 0 to the close dictionary
''')
choice = int(input("Enter your choice: "))
return choice
while(True):
word = input("\nEnter a word: ")
user_choice = menu()
match user_choice:
case 0:
print("Dictionary is closed")
exit(0)
case 1:
meaning = check_meaning(word)
print(meaning)
case 2:
antonym = get_antonym(word)
print(antonym)
case 3:
synonym = get_synonym(word)
print(synonym)
case 4:
print('''Enter a language code in which you want to translate word
Like for URDU language code is ur
For ARABIC language code is ar
For HINDI language code is hi
''')
lang_choice = input("Enter your choice: ")
trans = translate(word, lang_choice)
print(trans)
case _:
print("Invalid choice!")
#-------------------------------------------------------------
# Next tasks:
# 1- is to make this program in such a way that if word not exist then do something
# 2- also if user enter wrong word by mistake (for example if user want to enter ""happy"" but type "Haappyy") then do something
# 3- task number 2 is with get_close_matches() for difflib library
# 4- then make GUI application of this
#-------------------------------------------------------------