Challenge

Project 1 - English Dictionary App & Library Book Management System

Q1-A)English Dictionary App:

import pickle

def load_dictionary():
try:
with open('words.txt', 'rb') as file:
return pickle.load(file)
except FileNotFoundError:
return {}

def save_dictionary(dictionary):
with open('words.txt', 'wb') as file:
pickle.dump(dictionary, file)

def add_word():
dictionary = load_dictionary()
word = input('Enter the word: ')
meaning = input('Enter the meaning of the word: ')
dictionary[word] = meaning
save_dictionary(dictionary)
print(f'{word} has been successfully added to the dictionary.')

def find_meaning():
dictionary = load_dictionary()
word = input('Enter the word: ')
if word in dictionary:
print(f'{word}: {dictionary[word]}')
else:
print(f'{word} has not been found in the dictionary.')

def update_word():
dictionary = load_dictionary()
word = input('Enter the word you wish to update: ')
if word in dictionary:
meaning = input('Enter the updated meaning of the word: ')
dictionary[word] = meaning
save_dictionary(dictionary)
print(f'{word} has been successfully updated in the dictionary.')
else:
print(f'{word} not found in dictionary.')

def main():
while True:
print('Main Menu\n1. Add a new word\n2. Find the meaning\n3. Update a word\n4. Exit\n')
choice = input('Enter Choice: ')
if choice == '1':
add_word()
elif choice == '2':
find_meaning()
elif choice == '3':
update_word()
elif choice == '4':
break
else:
print('Invalid choice. Please try again.\n')

if __name__ == '__main__':
main()

Q1-B) Library Book Management System:

from tkinter import *
import sqlite3
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.messagebox as tkMessageBox

fullframe = Tk()
fullframe.title('A Library application')


def Database():
global conn,cursor
conn=sqlite3.connect('LBMS.db')
cursor=conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS library(booktitle TEXT, author TEXT, year INTEGER,ISBN INTEGER)")


def displaybook():
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM library 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()
conn.close()
tk.messagebox.showinfo('Library','Data fetched successfully')

def searchbook():
titleauthor=((author.get()).title())
titlebookname=((booktitle.get()).title())
publishedyear=((year.get()).title())
titleISBN=((ISBN.get()).title())
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM library")
fetch=cursor.fetchall()
count = 0

for data in fetch:
if(titlebookname==data[0]) and (titleauthor==data[1]) and (str(year.get())==str(data[2])) and (str(ISBN.get()==str(data[3]))):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(titlebookname==data[0]):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(titleauthor==data[1]):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(str(publishedyear)==str(data[2])):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
elif(str(titleISBN)==str(data[3])):
tree.insert('','end',values=(data[0],data[1],data[2],data[3]))
count+=1
if(count==0):
tk.messagebox.showinfo('Library','No book like this in library')
cursor.close()
conn.close()
author.set("")
booktitle.set("")
year.set("")
ISBN.set("")


def addbook():
Database()
titlebookname=((booktitle.get()).title())
titleauthor=((author.get()).title())
titlepublishedyear=str(year.get())
titleISBN=str(ISBN.get())

if ((titlebookname=='') or (titleauthor=='') or (titlepublishedyear=='') or (titleISBN=='')):
tk.messagebox.showinfo('Library','Please fill all the details')
else:
Database()
cursor.execute("INSERT INTO library(booktitle,author,year,ISBN) VALUES(?,?,?,?)",(titlebookname,titleauthor,titlepublishedyear,titleISBN))
conn.commit()
author.set("")
booktitle.set("")
year.set("")
ISBN.set("")
cursor.close()
conn.close()
tk.messagebox.showinfo('Library','values inserted')

def deletebook():
titleauthor = ((author.get()).title())
titlebookname = ((booktitle.get()).title())
titleISBN = ((ISBN.get()).title())
titlepublishedyear = (year.get().title())
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM library")
fetch = cursor.fetchall()
count = 0
for data in fetch:
if ((titlebookname == data[0]) and (titleauthor == data[1]) and (str(titleISBN == data[3])) and (str(titlepublishedyear == data[2]))):
tempa = ("'" + str(titlebookname) + "'")
tempb = ("'" + str(titleauthor) + "'")
tempp = ("'" + str(titlepublishedyear) + "'")
tempi = ("'" + str(titleISBN) + "'")
temp1 = "DELETE FROM library WHERE booktitle= " + tempa + " and author= " + tempb + " and year = " + tempp + " and ISBN= " + tempi
cursor.execute(temp1)
conn.commit()
count += 1

if count == 0:
tk.messagebox.showinfo('Library', 'No data with this name')
else:
tk.messagebox.showinfo('Library', 'Book deleted')
author.set("")
booktitle.set("")
year.set("")
ISBN.set("")
conn.commit()
cursor.close()
conn.close()

def issuebook():
titleauthor=((author.get()).title())
titlebookname=((booktitle.get()).title())
titleISBN=((ISBN.get()).title())
titlepublishedyear=(year.get().title())
tree.delete(*tree.get_children())
Database()
cursor.execute("SELECT * FROM library")
fetch=cursor.fetchall()
cursor.execute("DELETE FROM library")
count=0
for data in fetch:
if((titlebookname==data[0])and (titleauthor==data[1])and (str(titlepublishedyear==data[2]))and (str(titleISBN==data[3]))):
if(count==0):
count+=1
tk.messagebox.showinfo('Library','Book issued')
else:
cursor.execute("INSERT INTO library(booktitle,author,year,ISBN)VALUES(?,?,?,?)",(titlebookname,titleauthor,titlepublishedyear,titleISBN))
conn.commit()
else:
cursor.execute("INSERT INTO library(booktitle,author,year,ISBN)VALUES(?,?,?,?)",(titlebookname,titleauthor,titlepublishedyear,titleISBN))
conn.commit()
if(count==0):
tk.messagebox.showinfo('Library','No book with this detail in library')
author.set("")
booktitle.set("")
year.set("")
ISBN.set("")
conn.commit()
cursor.close()
conn.close()

def exit():
result=tkMessageBox.askquestion('Library','Do you want to exit (y/n)',icon='warning')
if(result=='yes'):
fullframe.destroy()
else:
tk.messagebox.showinfo('Library','You will now return to the application screen')

TitleFrame=Frame(fullframe,width=900,padx=20,bd=20,relief=RIDGE,bg='grey85')
TitleFrame.pack(side=TOP)
lblTitle=Label(TitleFrame,width=35,font=('Lucida Sans',40),text='Library Managment')
lblTitle.grid()

LeftFrame=Frame(fullframe,bd=20,width=500,height=520,padx=20,relief=RIDGE,bg='red')
LeftFrame.pack(side=LEFT)

ButtonFrame=Frame(LeftFrame,bd=20,width=250,padx=20,relief=RIDGE,bg='grey85')
ButtonFrame.pack(side=BOTTOM)

Form=Frame(LeftFrame,bd=20,width=620,height=520,padx=20,bg='grey85')
Form.pack()

RightFrame=Frame(fullframe,bd=20,width=620,height=520,padx=20,relief=RIDGE,bg='yellow')
RightFrame.pack(side=RIGHT)

author=StringVar()
booktitle=StringVar()
year=StringVar()
ISBN=StringVar()

lbl_authorname=Label(Form,text="Booktitle:",font=('Rockwell',15),fg='black')
lbl_authorname.grid(row=0,column=0,sticky='w')
entry_authorname=Entry(Form,textvariable=booktitle,width=25)
entry_authorname.grid(row=0,column=1)

lbl_bookname=Label(Form,text="Author:",font=('Rockwell',15), fg='black')
lbl_bookname.grid(row=1,column=0,sticky='w')
entry_bookname=Entry(Form,textvariable=author,width=25)
entry_bookname.grid(row=1,column=1)

lbl_publishedyear=Label(Form,text="Year:",font=('Rockwell',15),fg='black')
lbl_publishedyear.grid(row=2,column=0,sticky='w')
entry_publishedyear=Entry(Form,textvariable=year,width=25)
entry_publishedyear.grid(row=2,column=1)

lbl_ISBN=Label(Form,text="ISBN:",font=('Rockwell',15), fg='black')
lbl_ISBN.grid(row=3,column=0,sticky='w')
entry_ISBN=Entry(Form,textvariable=ISBN,width=25)
entry_ISBN.grid(row=3,column=1)

but_view=Button(ButtonFrame,text="Display",width=6,font=('Rockwell',14),command=displaybook,bg='grey85')
but_view.grid(row=1,column=0)

but_search=Button(ButtonFrame,text="Search",width=6,font=('Rockwell',14),command=searchbook,bg='grey85')
but_search.grid(row=1,column=1)

but_add=Button(ButtonFrame,text="Add",width=6,font=('Rockwell',14),command=addbook,bg='grey85')
but_add.grid(row=1,column=2)

but_issue=Button(ButtonFrame,text="Issue",width=6,font=('Rockwell',14),command=issuebook,bg='grey85')
but_issue.grid(row=1,column=3)

but_delete=Button(ButtonFrame,text="Delete",width=6,font=('Rockwell',14),command=deletebook,bg='grey85')
but_delete.grid(row=1,column=4)

but_exit=Button(ButtonFrame,text="Exit",width=6,font=('Rockwell',14),command=exit,bg='grey85')
but_exit.grid(row=1,column=5)

scrollbary=Scrollbar(RightFrame)
scrollbarx=Scrollbar(RightFrame)

col=('Book_Name','Author_Name','Published_year','ISBN')
tree=ttk.Treeview(RightFrame,columns=col,show='headings')
scrollbary=Scrollbar(RightFrame)
scrollbary.pack(side=RIGHT,fill=Y)
scrollbarx=Scrollbar(RightFrame)
scrollbarx.pack(side=BOTTOM,fill=X)

tree.heading("Book_Name",text="Booktitle",anchor=W)
tree.heading("Author_Name",text="Author",anchor=W)
tree.heading("Published_year",text="Year",anchor=W)
tree.heading("ISBN",text="ISBN",anchor=W)

tree.column("Author_Name",minwidth=0,width=150)
tree.column("Book_Name",minwidth=0,width=150)
tree.column("Published_year",minwidth=0,width=200)
tree.column("ISBN",minwidth=0,width=150)
tree.pack(side=TOP,fill=BOTH)

fullframe.configure(bg='grey85')
fullframe.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.