Python...
Python...
SUBMITTED TO
MAHARASHTRA BOARD OF TECHNICAL EDUCTAION
Report On
ENGLISH DICTIONARY USING PYTHON
Under Guidance Of
CERTIFICATE
This is to certify that
Sr.No Roll No. Name Enrollment No.
PWP for the academic Year 2024 – 2025 as prescribed in the MSBTE
Curriculum.
We would like to express our special thanks of gratitude to Mrs. Pooja Ahuja
who gave us a golden opportunity to showcase and let us learn more about our
topic i. e.“English Dictionary Using Python” and also taught us the way to work
in team. We would also like to Underscore dynamic efforts of the team work,
and their expert’s advice to complete this project in time.
02 Project scope 02
03 Mythology 03
04 Code 06
05 Output 11
06 Use Cases 13
08 Advantages &disadvantages 14
09 References 15
10 Conclusion 16
INTRODUCTION
➢ Deleting Words:
Allow users to delete words from the dictionary if they are no longer
needed or are mistakenly added.
➢ Persistent Storage:
Store the dictionary data in a JSON file, ensuring that all changes are
saved even after the program is closed.
➢ User-Friendly Interface:
Implement a simple menu-driven interface that is easy to navigate and
use through the command line.
➢ Error Handling:
Handle common errors like file reading issues, JSON decoding
problems, and invalid user inputs gracefully.
METHODOLOGY
1. Requirement Analysis:
7. Error Handling:
• Implement error handling for file reading, writing, and invalid user inputs.
• Provide meaningful error messages to guide the user.
8. Final Testing and Optimization:
11.Error Handling:
• Implement error handling for file reading, writing, and invalid user inputs.
• Provide meaningful error messages to guide the user.
12.Final Testing and Optimization:
class Dictionary:
def _init_(self, dictionary_file="dictionary.json"):
self.dictionary_file = dictionary_file
self.dictionary = self.load_dictionary()
def load_dictionary(self):
"""Load dictionary from JSON file or create new if not exists"""
if os.path.exists(self.dictionary_file):
try:
with open(self.dictionary_file, 'r') as file:
return json.load(file)
except json.JSONDecodeError:
print(f"Error reading dictionary file. Creating new dictionary.")
return {}
else:
print(f"Dictionary file not found. Creating new dictionary.")
return {}
def save_dictionary(self):
"""Save dictionary to JSON file"""
with open(self.dictionary_file, 'w') as file:
json.dump(self.dictionary, file, indent=4)
print(f"Dictionary saved to {self.dictionary_file}")
def lookup_word(self, word):
"""Look up a word in the dictionary"""
word = word.lower()
if word in self.dictionary:
return self.dictionary[word]
elif word.title() in self.dictionary:
return self.dictionary[word.title()]
elif word.upper() in self.dictionary:
return self.dictionary[word.upper()]
else:
# Find close matches
close_matches = get_close_matches(word, self.dictionary.keys(), n=3, cutoff=0.6)
if close_matches:
yn = input(f"Did you mean {close_matches[0]}? (Y/N): ")
if yn.lower() == 'y':
return self.dictionary[close_matches[0]]
else:
return f"Word '{word}' not found in dictionary."
else:
return f"Word '{word}' not found in dictionary."
def all_words(self):
"""Return a list of all words in the dictionary"""
return sorted(self.dictionary.keys())
def display_menu():
print("\n===== English Dictionary =====")
print("1. Look up a word")
print("2. Add a new word")
print("3. Update a word")
print("4. Delete a word")
print("5. List all words")
print("6. Import sample words")
print("7. Exit")
print("============================")
def import_sample_words(dictionary):
sample_words = {
"apple": "A round fruit with red, green, or yellow skin and a white flesh.",
"book": "A written or printed work consisting of pages bound together.",
"computer": "An electronic device capable of storing and processing data.",
"dictionary": "A book or electronic resource that lists words and their meanings.",
"elephant": "A very large animal with a long trunk and tusks.",
}
return dictionary.import_words(sample_words)
def main():
dictionary = Dictionary()
while True:
display_menu()
choice = input("Enter your choice (1-7): ")
if choice == '1':
word = input("Enter word to look up: ")
result = dictionary.lookup_word(word)
print(f"\nDefinition: {result}")
else:
print("Invalid choice. Please try again.")
if _name_ == "_main_":
main()
OUTPUT
USE CASES
DISADVANTAGES
1. Limited Search Functionality: The program only supports exact matches
or suggestions based on close matches, lacking advanced search features.
2. No Synonym or Antonym Support: Unlike comprehensive dictionaries, this
project lacks support for related words like synonyms and antonyms.
3. JSON File Vulnerability: If the JSON file gets corrupted or deleted, all
saved words will be lost, causing inconvenience.
4. No Multi-User Support: The application is designed for individual use, and
collaborative dictionary building is not supported.
5. Basic User Interface: The command-line interface may not be appealing
to users who prefer graphical interfaces.
REFERNCES
• https://docs.python.org/3/library/json.html
• https://www.w3schools.com/python/python_file_handling.asp
• https://docs.python.org/3/library/difflib.html
• https://realpython.com/comparing-python-command-line-parsing-libraries/
• https://www.json.org/json-en.html
• https://docs.python.org/3/library/json.html
• https://www.w3schools.com/python/python_file_handling.asp
CONCLUSION