6
6
def check_meaning (word ): # if user want to check meaning of word
7
7
return dictionary .meaning (word )
8
8
9
- def check_antonym (word ): # if user want to check antonym of word
9
+ def get_antonym (word ): # if user want to check antonym of word
10
10
return dictionary .antonym (word )
11
11
12
- def check_synonym (word ): # if user want to check synonym of word
12
+ def get_synonym (word ): # if user want to check synonym of word
13
13
return dictionary .synonym (word )
14
14
15
15
def translate (word ,language ): # if user want to translate word into other language
@@ -18,13 +18,14 @@ def translate(word,language): # if user want to translate word into other la
18
18
19
19
20
20
def menu ():
21
- print ("\n ----------------------------------------------" )
22
- print ("Enter 1 to check meaning of word" )
23
- print ("Enter 2 to check antonym of word" )
24
- print ("Enter 3 to check synonym of word" )
25
- print ("Enter 4 to translate word to other language" )
26
- print ("Enter 0 to the close dictionary" )
27
- print ()
21
+ print ('''
22
+ ----------------------------------------------
23
+ Enter 1 to check meaning of word
24
+ Enter 2 to get antonyms of word
25
+ Enter 3 to get synonyms of word
26
+ Enter 4 to translate word to other language
27
+ Enter 0 to the close dictionary
28
+ ''' )
28
29
29
30
choice = int (input ("Enter your choice: " ))
30
31
@@ -34,35 +35,31 @@ def menu():
34
35
while (True ):
35
36
word = input ("\n Enter a word: " )
36
37
user_choice = menu ()
37
-
38
- if user_choice == 0 :
39
- print ("Dictionary is closed" )
40
- exit (0 )
41
-
42
- elif user_choice == 1 :
43
- meaning = check_meaning (word )
44
- print (meaning )
45
-
46
- elif user_choice == 2 :
47
- antonym = check_antonym (word )
48
- print (antonym )
49
-
50
- elif user_choice == 3 :
51
- synonym = check_synonym (word )
52
- print (synonym )
53
-
54
- elif user_choice == 4 :
55
- print ("Enter a language code in which you want to translate word" )
56
- print ("Like for URDU language code is ur " )
57
- print ("For ARABIC language code is ar " )
58
- print ("For HINDI language code is hi " )
59
-
60
- lang_choice = input ("Enter your choice: " )
61
- trans = translate (word ,lang_choice )
62
- print (trans )
63
-
64
- else :
65
- print ("Invalid choice!" )
38
+ match user_choice :
39
+ case 0 :
40
+ print ("Dictionary is closed" )
41
+ exit (0 )
42
+ case 1 :
43
+ meaning = check_meaning (word )
44
+ print (meaning )
45
+ case 2 :
46
+ antonym = get_antonym (word )
47
+ print (antonym )
48
+ case 3 :
49
+ synonym = get_synonym (word )
50
+ print (synonym )
51
+ case 4 :
52
+ print ('''Enter a language code in which you want to translate word
53
+ Like for URDU language code is ur
54
+ For ARABIC language code is ar
55
+ For HINDI language code is hi
56
+ ''' )
57
+
58
+ lang_choice = input ("Enter your choice: " )
59
+ trans = translate (word , lang_choice )
60
+ print (trans )
61
+ case _:
62
+ print ("Invalid choice!" )
66
63
67
64
#-------------------------------------------------------------
68
65
0 commit comments