@@ -41,77 +41,77 @@ Feel free to explore and customize this project to suit your learning goals and
41
41
import sqlite3
42
42
43
43
class DictionaryApp :
44
- def __init__ (self , db_name ):
44
+ def __init__ (self ,db_name ):
45
45
self .conn = sqlite3.connect(db_name)
46
46
self .cursor = self .conn.cursor()
47
47
self .create_table()
48
48
49
49
def create_table (self ):
50
50
self .cursor.execute('''
51
- CREATE TABLE IF NOT EXISTS words (
51
+ CREATE TABLE IF NOT EXISTS words(
52
52
id INTEGER PRIMARY KEY,
53
53
word TEXT,
54
54
meaning TEXT,
55
- sentence TEXT
55
+ sentence TEXT
56
56
)
57
- ''' )
57
+ ''' )
58
58
self .conn.commit()
59
59
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))
62
62
self .conn.commit()
63
63
64
64
def list_words (self ):
65
65
self .cursor.execute(" SELECT * FROM words" )
66
66
words = self .cursor.fetchall()
67
67
return words
68
-
68
+
69
69
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 ()
72
72
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,))
76
76
self .conn.commit()
77
77
78
78
def close (self ):
79
79
self .conn.close()
80
80
81
81
def main ():
82
- dictionary = DictionaryApp(" words.db" )
83
-
82
+ dictionary = DictionaryApp(" words.db" )
84
83
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" :
95
93
word = input (" Word: " )
96
94
meaning = input (" Meaning: " )
97
95
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.. ." )
100
98
101
- elif choice == " 2" :
99
+ elif choice == " 2" :
102
100
words = dictionary.list_words()
103
101
if words:
104
- print (" \n Word List: " )
102
+ print (" \n Word List : " )
105
103
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 " )
109
107
110
108
elif choice == " 3" :
111
109
word = input (" Enter Word to Search: " )
110
+ print (word)
112
111
result = dictionary.search_word(word)
113
112
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 ]} " )
115
115
else :
116
116
print (" Word not found." )
117
117
@@ -126,6 +126,7 @@ def main():
126
126
127
127
if __name__ == " __main__" :
128
128
main()
129
+
129
130
```
130
131
131
132
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