Skip to content

Commit f7b2675

Browse files
authored
Merge pull request #6 from sandeeep-prajapati/main
a very small change in Dictionary Application.md file ........
2 parents c442167 + ac76ef9 commit f7b2675

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

Projects/Dictionary Application.md

+33-32
Original file line numberDiff line numberDiff line change
@@ -41,77 +41,77 @@ Feel free to explore and customize this project to suit your learning goals and
4141
import sqlite3
4242

4343
class DictionaryApp:
44-
def __init__(self, db_name):
44+
def __init__(self,db_name):
4545
self.conn = sqlite3.connect(db_name)
4646
self.cursor = self.conn.cursor()
4747
self.create_table()
4848

4949
def create_table(self):
5050
self.cursor.execute('''
51-
CREATE TABLE IF NOT EXISTS words (
51+
CREATE TABLE IF NOT EXISTS words(
5252
id INTEGER PRIMARY KEY,
5353
word TEXT,
5454
meaning TEXT,
55-
sentence TEXT
55+
sentence TEXT
5656
)
57-
''')
57+
''')
5858
self.conn.commit()
5959

60-
def add_word(self, word, meaning, sentence):
61-
self.cursor.execute("INSERT INTO words (word, meaning, sentence) VALUES (?, ?, ?)", (word, meaning, sentence))
60+
def add_word(self,word,meaning,sentence):
61+
self.cursor.execute("INSERT INTO words (word, meaning,sentence) VALUES ( ?, ?, ?)",(word,meaning,sentence))
6262
self.conn.commit()
6363

6464
def list_words(self):
6565
self.cursor.execute("SELECT * FROM words")
6666
words = self.cursor.fetchall()
6767
return words
68-
68+
6969
def search_word(self, word):
70-
self.cursor.execute("SELECT * FROM words WHERE word=?", (word,))
71-
word = self.cursor.fetchone()
70+
self.cursor.execute("SELECT * FROM words WHERE word LIKE ? ORDER BY word ASC", ('%' + word + '%',))
71+
word = self.cursor.fetchall()
7272
return word
73-
74-
def delete_word(self, word):
75-
self.cursor.execute("DELETE FROM words WHERE word=?", (word,))
73+
74+
def delete_word(self,word):
75+
self.cursor.execute('DELETE FROM words WHERE word = ?',(word,))
7676
self.conn.commit()
7777

7878
def close(self):
7979
self.conn.close()
8080

8181
def main():
82-
dictionary = DictionaryApp("words.db")
83-
82+
dictionary = DictionaryApp("words.db")
8483
while True:
85-
print("\nDictionary Application")
86-
print("1. Add Word")
87-
print("2. List Words")
88-
print("3. Search Word")
89-
print("4. Delete Word")
90-
print("5. Exit")
91-
92-
choice = input("Select an operation: ")
93-
94-
if choice == "1":
84+
print("\n Dictionary Application")
85+
print("1 : Add Words")
86+
print("2 : list Words")
87+
print("3 : Search Words")
88+
print("4 : Delete Words")
89+
print("5 : Exit")
90+
91+
choice = input("Select an operations : ")
92+
if choice == "1" :
9593
word = input("Word: ")
9694
meaning = input("Meaning: ")
9795
sentence = input("Example Sentence: ")
98-
dictionary.add_word(word, meaning, sentence)
99-
print("Word added.")
96+
dictionary.add_word(word,meaning,sentence)
97+
print("Word added successfully...")
10098

101-
elif choice == "2":
99+
elif choice == "2" :
102100
words = dictionary.list_words()
103101
if words:
104-
print("\nWord List:")
102+
print("\nWord List : ")
105103
for word in words:
106-
print(f"Word: {word[1]}, Meaning: {word[2]}, Example Sentence: {word[3]}")
107-
else:
108-
print("No words found.")
104+
print(f"Words : {word[1]}, \nMeaning : {word[2]}, \nExample Sentence : {word[3]}")
105+
else :
106+
print("no words are added here now")
109107

110108
elif choice == "3":
111109
word = input("Enter Word to Search: ")
110+
print(word)
112111
result = dictionary.search_word(word)
113112
if result:
114-
print(f"Word: {result[1]}, Meaning: {result[2]}, Example Sentence: {result[3]}")
113+
for word in result:
114+
print(f"Words : {word[1]}, \nMeaning : {word[2]}, \nExample Sentence : {word[3]}")
115115
else:
116116
print("Word not found.")
117117

@@ -126,6 +126,7 @@ def main():
126126

127127
if __name__ == "__main__":
128128
main()
129+
129130
```
130131

131132
This program creates a class called `DictionaryApp` that allows users to add words, list words, search for words, and delete words. It uses an SQLite database named "words.db" to store word data. Before running the program, make sure to create the "words.db" SQLite database file in the same directory or change the database name accordingly.

0 commit comments

Comments
 (0)