File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ # PYDICTIONARY
2
+
3
+ ## Description
4
+ This Python Dictionary works just like a normal dictionary of words and their meanings.
5
+
6
+ ## Steps To Execution
7
+ - Fork this repository and navigate to the PYDICTIONARY folder
8
+ - Execute the program by running the pydictionary.py file using ` $ python pydictionary.py `
9
+ - Enter any word of your choice and press enter
10
+ - The program will then print out the definition of the word you just entered and thats it!.
Original file line number Diff line number Diff line change
1
+ import json
2
+ from difflib import SequenceMatcher
3
+ from difflib import get_close_matches
4
+
5
+ # accessing the data.json file
6
+ data = json .load (open ("076 data.json" ))
7
+
8
+ # function to check if entered word is present in the 076_data.json file and print neccessary output
9
+ def translate (w ):
10
+ if w in data :
11
+ return data [w ]
12
+ elif w .title () in data :
13
+ return data [w .title ()]
14
+ elif w .upper () in data : #in case user enters words like USA or NATO
15
+ return data [w .upper ()]
16
+ elif len (get_close_matches (w ,data .keys ())) > 0 :
17
+ answer = input ("Did you mean %s instead? enter Y if yes or N if no:" % get_close_matches (w ,data .keys ())[0 ])
18
+ answer = answer .lower ()
19
+ if answer == "y" or answer == "yes" :
20
+ return data [get_close_matches (w ,data .keys ())[0 ]]
21
+ elif answer == "n" or answer == "no" :
22
+ return "TRY ANOTHER WORD:"
23
+ else :
24
+ return "We didn't Understand what you wanted Type y for yes and n for no: "
25
+ else :
26
+ print ("THE WORD DOESNT EXIST in the data.json database!!!!! " )
27
+
28
+ word = input ("Enter a word:" )
29
+
30
+ word = word .lower ()
31
+
32
+ print (translate (word ))
33
+ output = translate (word )
34
+ #can comment this below not so neccessary.....
35
+ if type (output ) == list :
36
+
37
+ for item in output :
38
+ print (item )
39
+ else :
40
+ print (output )
Original file line number Diff line number Diff line change @@ -52,6 +52,8 @@ When you Add a project Add it to the README for ease of finding it
52
52
53
53
* [ Sending Emails] ( https://github.com/larymak/Python-project-Scripts/tree/main/Sending-Emails )
54
54
55
+ * [ Python Dictionary] ( https://github.com/larymak/Python-project-Scripts/tree/main/PYDICTIONARY )
56
+
55
57
_ more coming soon_
56
58
57
59
_ contributions are welcomed, fork the repo and do the magic_
You can’t perform that action at this time.
0 commit comments