Skip to content

Commit c82013e

Browse files
committed
added new python dictionary project
1 parent 8dbee6f commit c82013e

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

PYDICTIONARY/076 data.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

PYDICTIONARY/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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!.

PYDICTIONARY/pydictionary.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ When you Add a project Add it to the README for ease of finding it
5252

5353
* [Sending Emails](https://github.com/larymak/Python-project-Scripts/tree/main/Sending-Emails)
5454

55+
* [Python Dictionary](https://github.com/larymak/Python-project-Scripts/tree/main/PYDICTIONARY)
56+
5557
_more coming soon_
5658

5759
_contributions are welcomed, fork the repo and do the magic_

0 commit comments

Comments
 (0)