Challenge

Project 1 - English Dictionary App & Library Book Management System

[{"metadata":{},"id":"e5edb209","cell_type":"markdown","source":"# Q1.A"},{"metadata":{"trusted":true},"id":"aaa4ee1d","cell_type":"code","source":"import json\nprint('Mainmenu \\n\\n 1.Add a word \\n 2.Find the meaning \\n 3.Update a word \\n 4.Exit \\n')\nwhile True:\n    try:\n        action=int(input('Please select from the given mainmenu(1,2,3,4):'))\n    except ValueError :\n        print('!!!!Please enter interger values only!!!')\n        print('*'*50)\n    else:\n        if action==4:\n            e=input('Are you sure you want to exit?(yes/no):')\n            if e=='Yes' or e=='yes':\n                print('Thank you have a nice day!!!')\n                print('*'*50)\n                break\n            else:\n                continue\n        elif action==1:\n            word=input('Enter a new word:')\n            meaning=input('Enter meaning of the word you entered:')\n            add={word:meaning}\n            with open('words.txt','a')as f:\n                f.write(json.dumps(add))\n                f.write('\\n')\n            print('Word added sucessfully')\n            print('*'*50)\n        elif action==2:\n            find=input('Enter a word to find its meaning:')\n            with open ('words.txt','r')as f:\n                data=f.read()\n                if find in data:\n                    print(f'Meaning of the word you entered is : {meaning}')\n                    print('*'*50)\n                    continue\n                else:\n                    print('Word not found')\n                    print('*'*50)\n        elif action==3:\n            oldword=input('Enter a word to be updated:')\n            with open ('words.txt','r')as f:\n                data=f.read()\n                if oldword in data:\n                    newword=input('Enter new a word:')\n                    data = data.replace(oldword,newword)\n                    with open(\"words.txt\", \"w\") as file:\n                          file.write(data)\n                    print(f'{oldword} has been updated to {newword}')\n                    print('*'*50)\n                    continue\n                else:\n                    print('Word not found')\n                    print('*'*50)\n        else:\n            print('!!!Please chose the correct option from the Mainmenu!!!')\n            print('*'*50)","execution_count":21,"outputs":[{"name":"stdout","output_type":"stream","text":"Mainmenu \n\n 1.Add a word \n 2.Find the meaning \n 3.Update a word \n 4.Exit \n\nPlease select from the given mainmenu(1,2,3,4):1\nEnter a new word:Madras\nEnter meaning of the word you entered:State of Tamilnadu\nWord added sucessfully\n**************************************************\nPlease select from the given mainmenu(1,2,3,4):2\nEnter a word to find its meaning:Madras\nMeaning of the word you entered is : State of Tamilnadu\n**************************************************\nPlease select from the given mainmenu(1,2,3,4):3\nEnter a word to be updated:Madras\nEnter new a word:Chennai\nMadras has been updated to Chennai\n**************************************************\nPlease select from the given mainmenu(1,2,3,4):4\nAre you sure you want to exit?(yes/no):yes\nThank you have a nice day!!!\n**************************************************\n"}]},{"metadata":{},"id":"902f2eca","cell_type":"markdown","source":"# Q1.B"},{"metadata":{"trusted":true},"id":"7c22e488","cell_type":"code","source":"import sqlite3 as sql \nimport tkinter as tk\nimport tkinter.ttk as ttk\nimport tkinter.messagebox as mb\nimport tkinter.simpledialog as sd\nfrom tkinter import *\n\n\nroot=Tk()\nroot.title('.....Library Management Application.....')\n\n\ndef Database():\n    global conn,cursor\n    conn=sql.connect('simple.db')\n    cursor=conn.cursor()\n    cursor.execute('CREATE TABLE IF NOT EXISTS Booklibrary(Bookname TEXT,Author TEXT,Year TEXT, ISBN TEXT)')\n\ndef create():\n    if BOOKNAME.get()==\"\" or AUTHOR.get()==\"\" or YEAR.get() ==\"\" or ISBN.get()==\"\":\n        txt_result.config(text='Please Enter all the fields',fd='red')\n    else:\n        Database()\n        cursor.execute('INSERT INTO Booklibrary(Bookname,Author,Year,ISBN)VALUES(?,?,?,?)',(str(BOOKNAME.get()),str(AUTHOR.get()),str(YEAR.get()),str(ISBN.get())))\n        conn.commit()\n        BOOKNAME.set(\"\")\n        AUTHOR.set(\"\")\n        YEAR.set(\"\") \n        #ISBN.set(\"\")\n        cursor.close()\n        conn.close()\n        txt_result.config(text='Record Inserted !',fg='green')\ndef Read():\n    tree.delete(*tree.get_children())\n    Database()\n    cursor.execute('SELECT * FROM Booklibrary ORDER BY Author ASC ')\n    fetch=cursor.fetchall()\n    for data in fetch:\n        tree.insert('','end',values=(data[0],data[1],data[2],data[3]))\n        cursor.close()\n        txt_result.config(text='Successfully fetched data !',fg='black')\ndef Exit():\n    result=mb.askquestion('Do you want to Exit ?(y/n)',icon='warning')\n    if result == 'yes':\n        root.destroy()\n        exit()\n\n\n#Variable\nBOOKNAME=StringVar()\nAUTHOR=StringVar()\nYEAR=StringVar() \nISBN=StringVar()\n\n\n\n #Frames\nTop=Frame(root,width=900,height=50,bg='blue',bd=8,relief='raise')\nTop.pack(side=TOP)\nLeft=Frame(root,width=300,height=500,bg='red',bd=8,relief='raise')\nLeft.pack(side=LEFT)\nRight=Frame(root,width=600,height=500,bg='yellow',bd=8,relief='raise')\nRight.pack(side=RIGHT)\n\n\nForms=Frame(Left,width=400,height=1000)\nForms.pack(side=\"top\")\n\n#buttons\nButtons=Frame(Left,width=300,height=100,bd=8,relief='raise')\nButtons.pack(side=\"bottom\")\n\n#Labels\ntxt_title=Label(Top,width=900,font=('arial',24),text='.....Library Management Application.....')\ntxt_title.pack()\ntxt_Bookname=Label(Forms,text='Bookname',font=('arial',16),bd=15)\ntxt_Bookname.grid(row=0,stick='e')\ntxt_Author=Label(Forms,text='Author',font=('arial',16),bd=15)\ntxt_Author.grid(row=1,stick='e')\ntxt_Year=Label(Forms,text='Year',font=('arial',16),bd=15)\ntxt_Year.grid(row=2,stick='e')\ntxt_ISBN=Label(Forms,text='ISBN',font=('arial',16),bd=15)\ntxt_ISBN.grid(row=3,stick='e')\ntxt_result=Label(Buttons)\ntxt_result.pack(side=TOP)\n\n#Entry widgets\nBookname=Entry(Forms,textvariable=BOOKNAME,width=30)\nBookname.grid(row=0,column=1)\nAuthor=Entry(Forms,textvariable=AUTHOR,width=30)\nAuthor.grid(row=1,column=1)\nYear=Entry(Forms,textvariable=YEAR,width=30)\nYear.grid(row=2,column=1)\nISBN=Entry(Forms,textvariable=ISBN,width=30)\nISBN.grid(row=3,column=1)\n\n#Button widgets\nbtn_display=Button(Buttons,width=10,text=\"Display\")\nbtn_display.pack(side=\"left\")\nbtn_search=Button(Buttons,width=10,text=\"Search\")\nbtn_search.pack(side=\"left\")\nbtn_add=Button(Buttons,width=10,text=\"Add\",command=create)\nbtn_add.pack(side=\"left\")\nbtn_issue=Button(Buttons,width=10,text=\"Issue\",command=Read)\nbtn_issue.pack(side=\"left\")                     \nbtn_delete=Button(Buttons,width=10,text=\"Delete\")\nbtn_delete.pack(side=\"left\")                     \nbtn_exit=Button(Buttons,width=10,text=\"Exit\",command=Exit)\nbtn_exit.pack(side=\"left\")      \n\n\n#list widgets\nscrollbary=Scrollbar(Right,orient=VERTICAL)\nscrollbarx=Scrollbar(Left,orient=HORIZONTAL)\n\ntree=ttk.Treeview(Right,columns=('Book','Author','Year','Isbn'))\n\nscrollbary.config(command=tree.yview)\nscrollbary.pack(side=\"right\",fill=Y)\nscrollbarx.config(command=tree.xview)\nscrollbarx.pack(side=\"bottom\",fill=X)\ntree.heading('Book',text='Book',anchor=W)\ntree.heading('Author',text='Author',anchor=W)\ntree.heading('Year',text='Year',anchor=W)\ntree.heading('Isbn',text='ISBN',anchor=W)\ntree.column('#0',stretch=NO,minwidth=0,width=0)\ntree.column('#1',stretch=NO,minwidth=0,width=80)\ntree.column('#2',stretch=NO,minwidth=0,width=120)\ntree.column('#3',stretch=NO,minwidth=0,width=160)\ntree.pack()\n#instaaliztion\nroot.mainloop()","execution_count":33,"outputs":[]}]
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.