Challenge

Project 1 - English Dictionary App & Library Book Management System

#projectA1 english Dictionary application

import json
from difflib import get_close_matches
import sys

def Add(): #add word and meaning
f = open('dict.json','r+')
words = json.load(f)
word = input('Enter word: ')
mean = input('Enter meaning : ')
words[word]=mean # it updates in dict
f.seek(0) # the positon of the curson to add word
json.dump(words,f,indent = 4) # word convrt which is exist in file extention
f.truncate()

# here i created a fucntion to find the meaning of the word
def Meaning():
words = json.load(open("dict.json","r")) #read file
word = input('Enter word to search : ')
word = word.lower() # it converts the entered word to lowercase and searches
if word in words:
print(words[word],'\n') # found word returns
elif word.title() in words: # it converts word to title case
print(words[word.title()],'\n')
elif word.upper() in words: #converts word to u-case as some acronyms are use u-case letters
print(words[word.upper()],'\n')


elif len(get_close_matches(word , words.keys())) > 0 : #check similer word check
print("did you mean %s instead\n" %get_close_matches(word, words.keys())[0])
decide = input("press y for yes or n for no : ")
if decide == "y":
print(words[get_close_matches(word , words.keys())[0]])
elif decide == "n":
print("Word Not Found \n")
else: # if user enter other than y and n then it throws an error
print("You have entered wrong input please enter just y or n :")
else:
print("Word Not Found \n")

# the following function is for updating an existing word in the text file.
def Update():
f = open("dict.json",'r+')# read file
words = json.load(f)
word = input('Enter the word to update: ')
if word in words: # if the word found in the file then it updates otherwise skips
meaning = input('Enter the meaning to update : ')
words[word] = meaning
f.seek(0)
else :
print("The word not exist in the data file \n")
json.dump(words,f,indent=4)
f.truncate()

def Exit():
print('Exiting the program.....\n')
sys.exit()

# displays main menu with four options.
def Menu():
print('Main Menu \n1.Add a new word\n2.Find the meaning\n3.Update a word\n4.Exit')

while True: # here i used while loop to iterate the selection if the user enters invalid choice by use untile correct input correct option.
choice = input('Select your option : ')
if choice == '1':
return Add()
elif choice == '2':
return Meaning()
elif choice == '3':
return Update()
elif choice == '4':
return Exit()
else:
print('You have selected invalid choice. Please select a valid key')

#main menu
while True:
Menu()

#Project B2 Library management system application

#Libraries
import sqlite3
import tkinter.ttk as ttk
from tkinter import*
import tkinter.messagebox as tkMessageBox

root = Tk()
root.geometry("850x450")
root.title('LIBRARY APPLICATION')

#Methon

def DataBase():
global conn,cursor
conn = sqlite3.connect('library.db')
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS data1(id INTEGER PRIMARY KEY AUTOINCREMENT ,Book TEXT,Author TEXT,Year TEXT,Isbn TEXT)")
conn.commit()

def Add():
conn = sqlite3.connect('library.db')
cursor = conn.cursor()
cursor.execute("INSERT INTO library(Book,Author,Year,Isbn) VALUES(?,?,?,?)",str(BOOK.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get()))
conn.commit()
conn.close()

def View():
conn = sqlite3.connect('library.db')
cursor = conn.cursor()
cursor.execute("SELECT * FROM library")
rows = cursor.fetchall()
conn.commit()
return rows

def Delete():
conn = sqlite3.connect('library.db')
cursor = conn.cursor()
cursor.execute("DELETE FROM library WHERE id =? ",(id,))
conn.commit()

def SearchData():
conn = sqlite3.connect('library.db')
cursor = conn.cursor()
cursor.execute("SELECT * FROM library where Book=? OR Author=? OR Year=? OR Isbn=?",str(BOOK.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get()))
rows = cursor.fetchall()
conn.commit()
conn.close()
return rows
def Update():
DataBase()
conn = sqlite3.connect('library.db')
cursor = conn.cursor()
cursor.execute("SELECT * FROM library where Book=? ,Author=?,Year=?,Isbn=?",str(BOOK.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get()))
conn.commit()

class library():
DataBase()
def __init__(self,window):
self.window = window
self.window.title("Libray Book Management")
#variable
Book= StringVar()
Author = StringVar()
Year = StringVar()
Isbn = StringVar()

def Exit():
result = tkMessageBox.askquestion("Do you want to exit? (y/n)",icon='warning')
if result=='yes':
root.destroy()
exit()


def Adddata():
if Book.get() == "" or Author.get() == "" or Year.get() == "":
tkMessagebox.showerror('Error','Please enter *marked values')
else:
library.Add(str(BOOK.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get()))
tree.delete(0,END)
tree.insert(END,str(BOOK.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get()))
self.Book.delete(0,END)
self.Author.delete(0,END)
self.Year.delete(0,END)
self.Isbn.delete(0,END)


def Display():
tree.delete(0,END)
Database()
for row in library.View():
tree.insert(END,row)

def SelectedBook(event):
global sb
search_book = tree.cursorselection()[0]
sb = tree.get(search_book)
self.Book.delete(0,END)
self.Book.insert(END,sb[1])
self.Author.delete(0,END)
self.Author.insert(END,sb[2])
self.Year.delete(0,END)
self.Year.insert(END,sb[3])
self.Isbn.delete(0,END)
self.Isbn.insert(END,sb[4])
txt_result.config(text="Book Present",fg='red')

def DeleteBook():
if (len(Book.get())!=0):
library.Delete(sb[0])
self.Book.delete(0,END)
self.Author.delete(0,END)
self.Year.delete(0,END)
self.Isbn.delete(0,END)

def Issue():
if (len(Book.get())!=0):
library.Delete(sb[0])
self.Book.delete(0,END)
self.Author.delete(0,END)
self.Year.delete(0,END)
self.Isbn.delete(0,END)
txt_result.config(text="Book Issued",fg='green')

def Search():
tree.delete(0,END)
for row in library.SearchData(Book.get(),Author.get(),Year.get(),Isbn.get()):
tree.insert(END,row)

#Frame
Top =Frame(root, width=300, height=20, bd=10, relief='raise',bg='pink')
Top.pack(side=TOP)
Left =Frame(root, width=150, height=400, bd=8, relief='raise',bg='yellow')
Left.pack(side=LEFT)

Right=Frame(root,width=150,height=400,bd=8,relief='raise',bg='green')
Right.pack(side=RIGHT)

Forms=Frame(Left,width=300,height=350)
Forms.pack(side=TOP)

Buttons =Frame(Left,width=150,height=100,bd=8,relief='raise')
Buttons.pack(side = BOTTOM)

#Labels
txt_title=Label(Top,width=200,height=2,text='Library Management System',font='Bodoni',bg="blue")
txt_title.pack()
txt_book=Label(Forms,text="Book:",font=('arial',10),bd=15)
txt_book.grid(row=0,stick='e')
txt_author=Label(Forms,text="Author:",font=('arial',10),bd=15)
txt_author.grid(row=1,stick='e')
txt_year=Label(Forms,text="Year:",font=('arial',10),bd=15)
txt_year.grid(row=2,stick='e')
txt_isbn=Label(Forms,text="Isbn:",font=('arial',10),bd=15)
txt_isbn.grid(row=3,stick='e')

#entry widget
book =Entry(Forms,textvariable=BOOK,width=30)
book.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)
isbn =Entry(Forms,textvariable=ISBN,width=30)
isbn.grid(row=3,column=1)

#buttons
btn_display=Button(Buttons,width=10,text='Display',command=Display)
btn_display.pack(side=LEFT)
btn_search=Button(Buttons,width=10,text='Search',command=Search)
btn_search.pack(side=LEFT)
btn_add=Button(Buttons,width=10,text='Add',command=Add)
btn_add.pack(side=LEFT)
btn_issue=Button(Buttons,width=10,text='Issue',command=Issue)
btn_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)

scrollbary=Scrollbar(Right,orient=VERTICAL)
scrollbarx=Scrollbar(Right,orient=HORIZONTAL)

tree = ttk.Treeview(Right,column=('Book','Author','Year','Isbn'))

scrollbary.config(command=tree.yview)
scrollbary.pack(side=RIGHT,fill=Y)
scrollbarx.config(command=tree.xview)
scrollbarx.pack(side=BOTTOM,fill=X)
tree.heading('Book',text='Book',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=0)
tree.column('#1',stretch=NO,minwidth=0,width=80)
tree.column('#2',stretch=NO,minwidth=0,width=80)
tree.column('#3',stretch=NO,minwidth=0,width=80)
tree.column('#4',stretch=NO,minwidth=0,width=80)
tree.pack()

#initialization
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.