Challenge

Project 1 - English Dictionary App & Library Book Management System

Project 1
This project uses the skills learnt from week 1 to week 6. The aim of this project is to create an English Dictionary app that returns definitions of English words. When the application is started, it displays a menu as follows:
Main Menu
Add a new word
Find the meaning
Update a word
Exit
Enter Choice:
If item 1 is selected, it should prompt for a word and then accept its meaning. This pair of word and its meaning should be stored in a file called ‘words.txt’. When item 2 is selected, it should prompt for a word, search that word in the file ‘words.txt’ and return the meaning if it is found. If the meaning is not found, it should display an appropriate message. Similarly, when choice 3 is entered, it should accept a word and update its meaning. In all the above three cases, the prompt should return to the main menu. The words and their meanings should be stored as a dictionary in words.txt, using the concept of serialization. If choice 4 is selected, a graceful exit should be performed.If you want to be recognized as a professional programmer, you have to practice more and develop applications in Python which you can include in your online portfolio. To achieve this, one such comprehensive project (with two small sub-projects inside it) is added which have to be completed by every student.
1A: English Dictionary App
This project uses the skills learnt from week 1 to week 6. The aim of this project is to create an English Dictionary app that returns definitions of English words.
import json
​
print('Welcom to the English Dictionary App!!')
print('Please select your choice...')
print('1 to Add a new number')
print('2 to Find the meaning of the word')
print('3 to Update a word')
print('4 to Exit')
​
​
f = open('words.txt','w')
dict = {}
json.dump(dict,f)
f.close()
​
while True:
    n = int(input('Please Enter a number : '))
    if n == 1:
        import json
        f = open('words.txt','w')
        w = input('Enter the word which you want to add : ')
        m = input('Enter the meaning of the word : ')
        dict[w] = m
        json.dump(dict,f)
        f.close()
    elif n == 2:
        import json
        f = open('words.txt','r+')
        dict=json.load(f)
        find = input('Enter the word which you want to find : ')
        if find in dict:
            print('The meaning of the word is : ',dict.get(find))
        else:
            print('We are Sorry, The word is not found!!')
            print('Find another word')
            
    elif n == 3:
        import json
        f = open('words.txt','w')
        u = input('Enter the word which you want to update : ')
        u_m = input('Enter the meaning of the word : ')
        dict[u] = u_m
        json.dump(dict,f)
        f.close()
        
    elif n == 4:
        print('Do you want to exit from the dictionary..!!')
        print('Plese enter Yes or No')
        a = input("Enter Yes/No to continue : ")
        if a=="Yes":
            print('Thank You for Choosing our Dictionary..')
            print('__'*20)
            break
        elif a=="No":
            print('Once again Welcome to the Dictionary....')
            continue
        else:
            print(" Invalid input!!..  Please,Enter either Yes/No")
            print('__'*20)
            
            
    else:
        print('Invalid Input!!!... Please choose a number given from above..')
        print('__'*10)
​
           
                
        
Welcom to the English Dictionary App!!
Please select your choice...
1 to Add a new number
2 to Find the meaning of the word
3 to Update a word
4 to Exit
Please Enter a number : 1
Enter the word which you want to add : apple
Enter the meaning of the word : fruit
Please Enter a number : 2
Enter the word which you want to find : grape
We are Sorry, The word is not found!!
Find another word
Please Enter a number : 3
Enter the word which you want to update : grape
Enter the meaning of the word : fruit
Please Enter a number : 4
Do you want to exit from the dictionary..!!
Plese enter Yes or No
Enter Yes/No to continue : no
 Invalid input!!..  Please,Enter either Yes/No
________________________________________
Please Enter a number : 2
Enter the word which you want to find : apple
The meaning of the word is :  fruit
Please Enter a number : 3
Enter the word which you want to update : apple
Enter the meaning of the word : orange
Please Enter a number : 2
Enter the word which you want to find : apple
The meaning of the word is :  orange
Please Enter a number : 4
Do you want to exit from the dictionary..!!
Plese enter Yes or No
Enter Yes/No to continue : Yes
Thank You for Choosing our Dictionary..
________________________________________
​
​
1B: Library Book Management System
In this project, a Library Book Management System will be implemented with the front end GUI developed using Tkinter and the backend database implemented in SQLite. It is a single window tkinter GUI application which will implement CRUD( create, read, update, delete) operations on a ‘books’ database, in SQLite. The window will contain text widgets to accept / display book title, author, year of publication, ISBN (optional) and a large text area/ list box to display the records which match the search criteria.
# Libraries:
​
from tkinter import *
import sqlite3
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessageBox
root = Tk()
root.title('Library Book Management System')
''
# Methods:
​
def Database():
    global con,cursor
    con = sqlite3.connect('books.db')
    cursor = con.cursor()
    cursor.execute("CREATE TABLE IF NOT EXISTS book(booktitle TEXT, author TEXT, yop TEXT, isbn TEXT)")
def Create():
    if (BOOKTITLE.get == "" or AUTHOR.get == "" or YOP == "" or ISBN.get == ""):
        txt_result.config(text = "Please, Enter all the Fields", fg = "red")
    else:
        Database()
        cursor.execute("Insert into book(booktitle,author,yop,isbn) VALUES(?,?,?,?)",(str(BOOKTITLE.get()),str(AUTHOR.get()),str(YOP.get()),str(ISBN.get())))
        con.commit()
        BOOKTITLE.set("")
        AUTHOR.set("")
        YOP.set("")
        ISBN.set("")
        cursor.close()
        con.close()
        txt_result.config(text = "Record inserted Successfully!",fg = "green")
def Read():
    tree.delete(*tree.get_children())
    Database()
    cursor.execute("Select * From book ORDER BY booktitle ASC")
    fetch=cursor.fetchall()
    for data in fetch:
        tree.insert('','end', values = (data[0],data[1],data[2],data[3]))
    cursor.close()
    txt_result.config(text = "Data Fetched Successfully!!", fg = "blue")
    
def Search():
    Database()
    cursor.execute("Select * From book where booktitle = ? or author = ? or yop = ? or isbn = ?", (str(BOOKTITLE.get()),str(AUTHOR.get()),str(YOP.get()),str(ISBN.get())))
    fetch = cursor.fetchall()
    for data in fetch:
        tree.insert('','end', values = (data[0],data[1],data[2],data[3]))
    cursor.close()
    txt_result.config(text = "Searched data ",fg = "black")
def Issue():
    Database()
    txt_result.config(text="Book is Issue.Thank you",fg = "red")
def Delete():
    Database()
    cursor.execute("Delete From book where booktitle = ? or author = ? or yop = ? or isbn = ?", (str(BOOKTITLE.get()),str(AUTHOR.get()),str(YOP.get()),str(ISBN.get())))
    cursor.close()
    txt_result.config(text = "Deleted Succssfully", fg = "red")
def Exit():
    result = tkMessageBox.askquestion("Do you Really want to Exit? (Y/N)", icon = "warning")
    if result == "Yes":
        root.destroy()
        exit()
# Variable Declaration:
​
BOOKTITLE = StringVar()
AUTHOR = StringVar()
YOP = StringVar()
ISBN = StringVar()
# FRAMES:
​
Top = Frame(root, width = 900, height = 50, bd = 8, relief = "raise")
Top.pack(side=TOP)
Left = Frame(root,width = 300,height = 500, bd = 8, relief = "raise")
Left.pack(side = LEFT)
Right = Frame(root,width = 600,height = 500, bd = 8, relief = "raise")
Right.pack(side = RIGHT)
Forms = Frame(Left, width = 300,height = 450)
Forms.pack(side = TOP)
Buttons = Frame(Left,width = 300,height = 100, bd = 8, relief = "raise")
Buttons.pack(side = BOTTOM)
​
# LABELS
​
txt_title = Label(Top, width = 900, font = ('arial',24),text = "Library Book Management System")
txt_title.pack()
txt_booktitle= Label(Forms, font = ('arial',16),text = "Book Title", bd = 15)
txt_booktitle.grid(row=0, stick = "e")
txt_author = Label(Forms,font=('arial',16),text = "Author", bd = 15)
txt_author.grid(row = 1,stick = "e")
txt_yop = Label(Forms,font=('arial',16),text = "YOP", bd = 15)
txt_yop.grid(row = 2,stick = "e")
txt_isbn = Label(Forms,font=('arial',16),text="ISBN",bd = 15)
txt_isbn.grid(row = 3,stick = "e")
​
txt_result = Label(Buttons)
txt_result.pack(side = TOP)
# ENTRY
​
booktitle = Entry(Forms, textvariable = BOOKTITLE, width=30)
booktitle.grid(row =0, column =1)
author = Entry(Forms, textvariable = AUTHOR, width=30)
author.grid(row =1, column =1)
yop = Entry(Forms, textvariable = YOP, width=30)
yop.grid(row =2, column =1)
isbn = Entry(Forms, textvariable = ISBN, width=30)
isbn.grid(row =3, column =1)
# BUTTONS
​
btn_read = Button(Buttons,width = 10,text = 'Display',command=Read)
btn_read.pack(side=LEFT)
​
but_search = Button(Buttons,width = 10,text = 'Search',command=Search)
but_search.pack(side=LEFT)
​
btn_create = Button(Buttons, width = 10, text = "Add", command = Create)
btn_create.pack(side=LEFT)
​
but_issue = Button(Buttons,width = 10,text = 'Issue',command=Issue)
but_issue.pack(side=LEFT)
​
btn_delete = Button(Buttons,width = 10,text = 'Delete',command=Delete)
btn_delete.pack(side=LEFT)
​
btn_exit = Button(Buttons,width = 10,text = 'Exit',command=Exit)
btn_exit.pack(side=LEFT)
# LIST
​
scrollbary = Scrollbar(Right,orient=VERTICAL)
scrollbarx = Scrollbar(Right,orient=HORIZONTAL)
​
tree = ttk.Treeview(Right,columns=("Book Title","Author","Yop","Isbn"))
​
scrollbary.config(command=tree.yview)
scrollbary.pack(side=RIGHT,fill=Y)
​
scrollbarx.config(command=tree.xview)
scrollbary.pack(side=BOTTOM,fill=X)
​
tree.heading('Book Title',text="Booktitle",anchor=W)
tree.heading('Author',text="Author",anchor=W)
tree.heading('Yop',text="Yop",anchor=W)
tree.heading('Isbn',text="ISBN",anchor=W)
​
tree.column("#0",stretch=NO,minwidth=0,width=0)
tree.column("#1",stretch=NO,minwidth=0,width=100) 
tree.column("#2",stretch=NO,minwidth=0,width=60)
tree.column("#3",stretch=NO,minwidth=0,width=60)
tree.column("#4",stretch=NO,minwidth=0,width=80)
tree.pack()
# initialisation
​
if __name__ == '__main__':
    root.mainloop()
​
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.