Challenge

Project 1 - English Dictionary App & Library Book Management System

English Dictionary app

In [1]:
# Import the modules required
import json
from difflib import get_close_matches
# Loading data from json file
# in python dictionary
data = json.load(open("data.json"))
    
def getMeaning(w):
    w=w.lower()
    if w in data:
        return data[w]
    elif len(get_close_matches(w,data.keys())) > 0:
        close_match = get_close_matches(w,data.keys()) [0]
        print("Did you mean % s instead? Enter Y if yes, or N if no:"%close_match)
        choice = input()
        if choice == 'Y':
            return data[close_match]
        elif choice == 'n':
            return "The word doesn't exixts. Please double check it."
        else:
            return "Sorry,we didn't understand your entry"        
    else:
        return "The word doesn't exixts. Please double check it."
    if type (meaning) == list:
        for item in meaning:
            print(item)
        else:
            print(meaning)
# Driver code
word = input("Enter word: ")
output = getMeaning(word)
  
if type(output) == list:
    for item in output:
        print(item)
else:
    print("Meaning:   ",output)
input('Press ENTER to exit')


Library Management System

 from tkinter import *
from sqlite3 import *
import tkinter.ttk as ttk
import tkinter.messagebox as tkMassgeBox
def Database():
    global conn,cursor
    conn=connect("Library.db")
    cursor=conn.cursor()
    cursor.execute("CREATE TABLE IF NOT EXISTS lbms(author_name TEXT,book_title TEXT,year INTEGER,ISBN INTEGER)")
 
def display_all_records():
    present.delete(*present.get_children())
    Database()
    cursor.execute("SELECT * FROM lbms ORDER by book_title ASC")
    fetch=cursor.fetchall()
    for data in fetch:
        present.insert('','end',values=(data[0],data[1],data[2],data[3]))
    conn.close()
    Ll1.config(text="Please see the books!",fg="green")
 
def add_new_book():
    Database()
    if author_name.get(1.0,"end-1c")!="" and book_title.get(1.0,"end-1c")!="" and year.get(1.0,"end-1c")!="" and ISBN.get(1.0,"end-1c")!="":
        cursor.execute("INSERT INTO lbms VALUES(?,?,?,?)",(author_name.get(1.0,"end-1c"),book_title.get(1.0,"end-1c"),int(year.get(1.0,"end-1c")),int(ISBN.get(1.0,"end-1c"))))
        conn.commit()
        delete()
        conn.close()
        Ll1.config(text="Book is added successfully!",fg="green")
    else:
        Ll1.config(text="Please enter all the values to add the book!",fg="red")
        delete()
 
def Search_book():
    present.delete(*present.get_children())
    Database()
    if str(author_name.get(1.0,"end-1c"))!="":
        name="'"+str(author_name.get(1.0,"end-1c")).title()+"'"
        temp="SELECT * FROM lbms WHERE author_name = "+name
        cursor.execute(temp)
        fetch=cursor.fetchall()
        for data in fetch:
            present.insert('','end',values=(data[0],data[1],data[2],data[3]))
        Ll1.config(text="Please see the books!",fg="green")
    elif str(book_title.get(1.0,"end-1c"))!="":
        name="'"+str(book_title.get(1.0,"end-1c")).title()+"'"
        temp="SELECT * FROM lbms WHERE book_title = "+name
        cursor.execute(temp)
        fetch=cursor.fetchall()
        for data in fetch:
            present.insert('','end',values=(data[0],data[1],data[2],data[3]))
        Ll1.config(text="Please see the books!",fg="green")
    elif str(year.get(1.0,"end-1c"))!="":
        temp="SELECT * FROM lbms WHERE year = "+str(year.get(1.0,"end-1c"))
        cursor.execute(temp)
        fetch=cursor.fetchall()
        for data in fetch:
            present.insert('','end',values=(data[0],data[1],data[2],data[3]))
        Ll1.config(text="Please see the books!",fg="green")
    elif str(ISBN.get(1.0,"end-1c"))!="":
        temp="SELECT * FROM lbms WHERE ISBN = "+str(ISBN.get(1.0,"end-1c"))
        cursor.execute(temp)
        fetch=cursor.fetchall()
        for data in fetch:
            present.insert('','end',values=(data[0],data[1],data[2],data[3]))
        Ll1.config(text="Please see the books!",fg="green")
    else:
        Ll1.config(text="Please enter at least single identity!",fg="red")
    delete()
    conn.close()
 
def issue_the_book():
    Database()
    selected_item=present.selection()
    if len(selected_item)>0:
        present.delete(selected_item)
        Ll1.config(text="Selected book is issued!",fg="green")
    else:
        Ll1.config(text="Please select a book from library to issue!",fg="red")
    delete()
    conn.close()
 
def delete_book():
    Database()
    if author_name.get(1.0,"end-1c")=="" or book_title.get(1.0,"end-1c")=="" or year.get(1.0,"end-1c")=="" or ISBN.get(1.0,"end-1c")=="":
        Ll1.config(text="Please enter all Entries!",fg="red")
        delete()
    else:
        author='"'+str(author_name.get(1.0,"end-1c"))+'"'
        book='"'+str(book_title.get(1.0,"end-1c"))+'"'
        y=str(year.get(1.0,"end-1c"))
        I=str(ISBN.get(1.0,"end-1c"))
        temp="DELETE FROM lbms WHERE author_name LIKE "+author+" and book_title LIKE "+book+" and year = "+y+" and ISBN = "+I
        cursor.execute(temp)
        conn.commit()
        Ll1.config(text="Book deleted successfully!",fg='green')
        delete()
    conn.close()
 
def delete():
    author_name.delete("1.0","end")
    book_title.delete("1.0","end")
    year.delete("1.0","end")
    ISBN.delete("1.0","end")
def Exit():
    result=tkMassgeBox.askquestion("Do you want to exit? (y/n)",icon="warning")
    if result=="yes":
        root.destroy()
        exit()
root=Tk()   
root.geometry("900x400")
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)

inner_upper=Frame(Left,width=300,height=250,bd=8,relief="raise")
inner_upper.pack(side=TOP)
 
L1=Label(Top,text=" Library Book Management System ",font=("arial",20))
L1.pack()

L2=Label(inner_upper,text="Author Name:",font=("arial",14))
L3=Label(inner_upper,text="Book Name:",font=("arial",14))
L4=Label(inner_upper,text="Published year:",font=('arial',14))
L5=Label(inner_upper,text="ISBN:",font=('arial',14))
author_name=Text(inner_upper,height=2,width=40)
book_title=Text(inner_upper,height=2,width=40)
year=Text(inner_upper,height=2,width=40)
ISBN=Text(inner_upper,height=2,width=40)
L2.grid(row=0,column=0)
author_name.grid(row=0,column=1)
L3.grid(row=1,column=0)
book_title.grid(row=1,column=1)
L4.grid(row=2,column=0)
year.grid(row=2,column=1)
L5.grid(row=3,column=0)
ISBN.grid(row=3,column=1)

Ll1=Label(Right)
Ll1.pack(side=BOTTOM)
inner_frame=Frame(Left,width=250,height=50,bd=8,relief='raise')
inner_frame.pack(side=BOTTOM)
Bb1=Button(inner_frame,text="View Library",command=display_all_records)
Bb1.grid(row=0,column=0)
Bb2=Button(inner_frame,text="Search",command=Search_book)
Bb2.grid(row=0,column=1)
Bb3=Button(inner_frame,text="Add New Book",command=add_new_book)
Bb3.grid(row=0,column=2)
Bb4=Button(inner_frame,text="Issue the Book",command=issue_the_book)
Bb4.grid(row=0,column=3)
Bb5=Button(inner_frame,text="Delete the Book",command=delete_book)
Bb5.grid(row=0,column=4)
Bb6=Button(inner_frame,text="Exit",command=Exit)
Bb6.grid(row=0,column=5)
scrollbary=Scrollbar(Right,orient=VERTICAL)
scrollbarx=Scrollbar(Right,orient=HORIZONTAL)
present = ttk.Treeview(Right)
scrollbary.config(command=present.yview)
scrollbary.pack(side=RIGHT,fill=Y)
scrollbarx.config(command=present.xview)
scrollbarx.pack(side=BOTTOM,fill=X)
present['columns']=("Author Name","Book Name","Published year","ISBN no")
present.column('#0', width=0, stretch=NO)
present.column('Author Name', anchor=CENTER, width=100)
present.column('Book Name', anchor=CENTER, width=100)
present.column('Published year', anchor=CENTER, width=100)
present.column('ISBN no', anchor=CENTER, width=100)
present.heading('#0', text='', anchor=CENTER)
present.heading('Author Name', text='Author Name', anchor=CENTER)
present.heading('Book Name', text='Book Name', anchor=CENTER)
present.heading('Published year', text='Published year', anchor=CENTER)
present.heading('ISBN no', text='ISBN no', anchor=CENTER)

present.pack()
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.