Skip to content

Commit 78004c9

Browse files
authored
Merge pull request Shahrayar123#9 from Code-xed/patch-2
Update dictionary.py
2 parents 1d0e226 + d2e549b commit 78004c9

File tree

1 file changed

+35
-38
lines changed

1 file changed

+35
-38
lines changed

Dictionary-App/dictionary.py

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
def check_meaning(word): # if user want to check meaning of word
77
return dictionary.meaning(word)
88

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
1010
return dictionary.antonym(word)
1111

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
1313
return dictionary.synonym(word)
1414

1515
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
1818

1919

2020
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+
''')
2829

2930
choice = int(input("Enter your choice: "))
3031

@@ -34,35 +35,31 @@ def menu():
3435
while(True):
3536
word = input("\nEnter a word: ")
3637
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!")
6663

6764
#-------------------------------------------------------------
6865

0 commit comments

Comments
 (0)