Skip to main content

GRADE XI : DICTIONARY PROJECT

 

DICTIONARY PROJECT

GRADE XI

 

Write a program to create a dictionary BOOK with the following elements where each element has bookno as the key field and name, price, quantity, amount, calculated as price and quantity. The category is to be calculated as follows:

Category       

Fic

Encyl

Acad

Other

Discount

15% of amount

12% of amount

10% of amount

 500

Write a menu driven program to do the following operations:

a. Display all the records.

b. Search and display records on the basis of:

i.Book No

ii.Name

 c. Display the maximum amount.

d. Display the average according to the following criteria:

i. Average of amount of all books

ii. Average of amount of user given category

 

e. Edit the record on the basis of:

i. A user given book no

ii. A user given book name

 

f. Count the records on the basis of the following:

i. Count all records

ii. Count on the basis of a user given category

iii. Count on the basis of amount greater than user given amount.

 




SOLUTION


BOOK={}

n=int(input("Enter number of elements"))

for i in range(n):

    bookno=int(input("Enter book number"))

    nm=input("Enter book name")

    price=float(input("Enter price of book"))

    qtty=int(input("Enter quantity"))

    cat=input("Enter category of book")

    amt=qtty*price

    if cat=='Fic':

        dis=0.15*amt

    elif cat=='Encyl':

        dis=0.12*amt

    elif cat=='Acad':

        dis=0.1*amt

    else:

        dis=500

    BOOK[bookno]=[nm,cat,qtty,price,amt,dis]

                                   # 0   1    2    3     4     5

ans='y'

while ans== 'y' or 'Y':

    print("1.All records\n2.Search record\n3.Maximum amount\n4.Average\n5.Edit record\n6.Count records")

    ch=int(input("Enter choice"))

    if ch==1:

        for i in BOOK:

            print(BOOK[i],end="\n")

            

    elif ch==2:

        opt1=int(input("1.Search by book number\n2.Search by name\n "))

        if opt1==1:

            sbno=int(input("Enter book number to search"))

            for i in BOOK:

                if i==sbno:

                    print(BOOK[i])

        elif opt1==2:

            snm=input("Enter name to search")

            for i in BOOK:

                if BOOK[i][0]==snm:

                    print(BOOK[i])

                    

    elif ch==3:

        max=0

        for i in BOOK:

            if BOOK[i][4]>max:

                max=BOOK[i][4]

        print("The maximum amount is:",max)

            

    elif ch==4:

        opt2=int(input("1.Average amount of all books\n2.Average amount of books of a given category\n"))

        if opt2==1:

            s=0 

            for i in BOOK:

                s+=BOOK[i][4]

            print("Average amount of all books is:",s/n)

            

        elif opt2==2:

            scat=input("Enter category of books to find average")

            s,ctr=0,0 

            for i in BOOK:

                if BOOK[i][1]== scat:

                    s+=BOOK[i][4]

                    ctr+=1

            print("Average amount of books of",scat,"is:",s/ctr)

            

    elif ch==5:

        opt3=int(input("1.Edit record by book number\n2.Edit record by book name\n"))

        if opt3==1:

            sbn=int(input("Enter book number"))

            for i in BOOK:

                if i==sbn:

                    BOOK[i][0]=input("Enter new name")

                    BOOK[i][1]=input("Enter new category")

                    BOOK[i][2]=int(input("Enter new quantity"))

                    BOOK[i][3]=float(input("Enter new price"))

                    BOOK[i][4]==float(input("Enter new ammount"))

                    BOOK[i][5]==float(input("Enter new discount"))

            print(BOOK[i])

            

        elif opt3==2:

            sn=input("Enter book name")

            for i in BOOK:

                if BOOK[i][0]==sn:

                    BOOK[i][0]=input("Enter new name")

                    BOOK[i][1]=input("Enter new category")

                    BOOK[i][2]=int(input("Enter new quantity"))

                    BOOK[i][3]=float(input("Enter new price"))

                    BOOK[i][4]==float(input("Enter new ammount"))

                    BOOK[i][5]==float(input("Enter new discount"))

            print(BOOK[i])

            

    elif ch==6:

        opt4=int(input("1.Count all records\n2.Count records of a category\n3.Count on basis of amount\n"))

        if opt4==1:

            ctr=0

            for i in BOOK:

                ctr+=1

            print("There are",ctr,"records in BOOK")

            

        elif opt4==2:

            sca=input("Enter category")

            ctr=0

            for i in BOOK:

                if sca==BOOK[i][1]:

                    ctr+=1

            print("There are",ctr,"records of",sca,"category")

            

        elif opt4==3:

            samt=int(input("Enter amount"))

            ctr=0

            for i in BOOK:

                if BOOK[i][4]>samt:

                    ctr+=1

            print(ctr,"books have amount greater than",samt)

            

    else:

        print("Wrong Choice")

ans=input("Do you want to go back to the menu(y/n):")

Comments

Popular posts from this blog

GRADE XII - Python Connectivity with MySQL

  Python Connectivity with MySQL In real-life applications, the data inputted by the user and processed by the application needs to be saved permanently, so that it can be used for future manipulation. Usually, input and output data is displayed during execution but not stored, as it resides in main memory , which is temporary — i.e., it gets erased once the application is closed. This limitation can be overcome by sending the data to be stored in a database , which is made accessible to the user through a Front-End interface . Key Concepts Database A database is an organized collection of data that is stored and accessed electronically from a computer system. DBMS (Database Management System) A DBMS is software that interacts with end-users, applications, and the database to capture and analyze data. Front-End The Front-End is the user interface of the application, responsible for input/output interaction with the user. Back-End The Back-End refe...

GRADE XI | DESIGN THINKING & INNOVATION (848) | INTRO | CH-1

  DESIGN THINKING &  INNOVATION (848)  INTRODUCTION LINK : INTRODUCTION PPT PPT LINK Notes: Design Thinking and Innovation Grade XI Introduction Section   I. What is Design? (0.1.1) Definitions from Experts: John Maeda: "Design is solution to a problem". Saul Bass: "Design is thinking made visual". Charles Eames:   “Design is a plan for arranging elements in such a way as best to accomplish a particular purpose.” Steve Jobs:  "Design is not just what it looks like and feels like. Design is how it works". Prof. Sudhakar Nadkarni:  "Essentials of design are— purity, precision, details". Design is a way of understanding needs, identifying problems, and creating appropriate and innovative solutions. It is not only about appearance, but also about usefulness and sustainability. Design is explained as something that helps solve problems and make a positive difference. Key ...