Challenge

Project 1 - English Dictionary App & Library Book Management System

http://localhost:8888/notebooks/python challenge/Project1 python.ipynb

my_dict = {}

def main():

    print(" *** Welcome to the English Dictionary App *** ")

    while True:

        print("1. Add a new word")

        print("2. Find the meaning")

        print("3. Update a word")

        print("4. Exit")

        ch = input("enter the choice: ",)

        if ch == "1":

            word=input("Enter the word",)

            meaning=input("meaning of the word",)

            add_word(word,meaning)

            print("word added to the file")

        elif ch == "2":

            word=input("enter the word",)

            meaning=find_word(word)

            if meaning == 0:

                print("word is not found")

            else:

                print(word,":",meaning)

        elif ch == "3":

            word = input("enter the word",)

            meaning = input('enter the meaning to be updated',)

            res = update_word(word,meaning)

            print(res)

        elif ch=="4":

            print("Thank You")

        else:

            print("invalid choice")

def add_word(word,meaning):

    my_dict[word]=meaning

    f=open("words.txt","w")

    json.dump(my_dict,f)

    f.close()

def find_word(word):

    f = open("words.txt","r")

    my_dict = json.load(f)

    if word in my_dict:

        return my_dict[word]

    else:

        return 0

    f.close()

def update_word(word,meaning):

    f = open("words.txt","r")

    my_dict = json.load(f)

    f.close()

    if word in my_dict:

        my_dict[word] = meaning

        f =open("words.txt","w")

        json.dump(my_dict,f)

        f.close()

        return "word updated !"

    else:

        return 'Word not found'

main() 

 2] Library Book Management System

Aim: Library Book Management System will be implemented with the front end GUI developed using Tkinter and the backend database implemented in SQLite. 

The Program is written as follow:

 

#-------------------------------------------Library------------------------------------------------------------------
import sqlite3
from tkinter import*
import tkinter.ttk as ttk 
import tkinter.messagebox as tkMessageBox

#---------------------------------------------Background Photo------------------------------------------------------
root=Tk()
root.title("Libary Book Management")

bg = PhotoImage(file = "cos.png")

label = Label(root,image = bg)
label.place(x=0,y=0)

#------------------------------------------Fuctions-----------------------------------------------------------
def Database():
    global conn,cursor
    conn = sqlite3.connect('lab.db')
    cursor = conn.cursor()
    cursor.execute("CREATE TABLE IF NOT EXISTS lab(booktitle TEXT,author TEXT,year TEXT,isbn TEXT)")

def Add():
        Database()
        if BOOKTITLE.get()=="" or AUTHOR.get()=="" or YEAR.get()==""or ISBN.get()=="":
            txt_result.config(text="Please enter all values",fg="red")
        else:
            cursor.execute("INSERT INTO lab(booktitle,author,year,isbn) values(?,?,?,?)",[str(BOOKTITLE.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get())])
            conn.commit()
            BOOKTITLE.set("")
            AUTHOR.set("")
            YEAR.set("")
            ISBN.set("")
            cursor.close()
            conn.close()
            txt_result.config(text="Record Inserted",fg="green")

def Display():
    Database()
    cursor.execute("SELECT * FROM lab 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="Successful fetch data",fg="black")
    
def Search():
    Database()
    cursor.execute("SELECT * FROM lab WHERE booktitle = ? or author = ? or year = ? or isbn=? ",[str(BOOKTITLE.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get())])
    rows=cursor.fetchall()
    for data in rows:
        tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
    cursor.close()

def Issue():
    Database()
    txt_result.config(text="Book is Issue.Thank you",fg = "green")
        
def Delete():
    Database()
    cursor.execute("DELETE FROM lab WHERE booktitle = ? or author = ? or year = ? or isbn=? ",[str(BOOKTITLE.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get())])
    cursor.close()
    txt_result.config(text="Successfully Deleted!!!",fg="red")
    
def Exit():
    result = tkMessageBox.askquestion('Do you want to exit? (y/n)',icon='warning')
    if result == "yes":
        root.destroy()
        exit() 
#-----------------------------------------------Variable Decleartion-------------------------------------------------

BOOKTITLE = StringVar()
AUTHOR = StringVar()
YEAR = StringVar()
ISBN = StringVar()

#--------------------------------------------------Frame------------------------------------------------------------- 

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,relief = 'raise')
Buttons.pack(side = BOTTOM)
# -------------------------------------------------Label-------------------------------------------------------------
txt_title = Label(Top,width=900,font=('arial',24),text='Libary Book Management')
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_year = Label(Forms,font=('arial',16),text='Year',bd=15)
txt_year.grid(row=2,stick='e')

txt_isbm = Label(Forms,font=('arial',16),text='ISBN',bd=15)
txt_isbm.grid(row=3,stick='e')

txt_result = Label(Buttons)
txt_result.pack(side=TOP)
#--------------------------------------------------Entery------------------------------------------------------------
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)

year = Entry(Forms,textvariable = YEAR,width=30)
year.grid(row=2,column=1)

isbm = Entry(Forms,textvariable = ISBN,width=30)
isbm.grid(row=3,column=1)

#---------------------------------------------Buttons----------------------------------------------------------
but_read = Button(Buttons,width = 10,text = 'Display',command=Display)
but_read.pack(side=LEFT)

but_search = Button(Buttons,width = 10,text = 'Search',command=Search)
but_search.pack(side=LEFT)

but_create = Button(Buttons,width = 10,text = 'Add',command=Add)
but_create.pack(side=LEFT)

but_issue = Button(Buttons,width = 10,text = 'Issue',command=Issue)
but_issue.pack(side=LEFT)

but_delete = Button(Buttons,width = 10,text = 'Delete',command=Delete)
but_delete.pack(side=LEFT)

but_exit = Button(Buttons,width = 10,text = 'Exit',command=Exit)
but_exit.pack(side=LEFT)

#----------------------------------------------------List-------------------------------------------------------
scrollbary = Scrollbar(Right,orient=VERTICAL)
scrollbarx = Scrollbar(Right,orient=HORIZONTAL)

tree = ttk.Treeview(Right,columns=("BookTitle","Author","Year","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('BookTitle',text="Booktitle",anchor=W)
tree.heading('Author',text="Author",anchor=W)
tree.heading('Year',text="Year",anchor=W)
tree.heading('Isbn',text="ISBN",anchor=W)

tree.column("#0",stretch=NO,minwidth=0,width=20)
tree.column("#1",stretch=NO,minwidth=0,width=180) 
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()
#------------------------------------------Ending loop---------------------------------------------------------------
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.