@@ -41,77 +41,77 @@ Feel free to explore and customize this project to suit your learning goals and
4141import sqlite3
4242
4343class 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
8181def main ():
82- dictionary = DictionaryApp(" words.db" )
83-
82+ dictionary = DictionaryApp(" words.db" )
8483 while True :
85- print (" \n Dictionary 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 (" \n Word List: " )
102+ print (" \n Word 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 ]} , \n Meaning : { word[2 ]} , \n Example 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 ]} , \n Meaning : { word[2 ]} , \n Example Sentence : { word[3 ]} " )
115115 else :
116116 print (" Word not found." )
117117
@@ -126,6 +126,7 @@ def main():
126126
127127if __name__ == " __main__" :
128128 main()
129+
129130```
130131
131132This 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