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 XII - CSV FILE

CSV FILE (COMMA SEPERATED VALUE) CSV NOTES LINK :  CSV NOTES - CLICK HERE Writing data to a CSV file involves the following steps: Import the csv module Open the CSV file in write mode ( "w" ) using open() Create the writer object Write the data into the file using the writer object Close the file using close() writerow() Method This method is used to write a single row to a CSV file. It takes a sequence (list or tuple) as its parameter, and writes the items as a comma-separated line in the file. You do not need to add a newline character (\n) — it automatically places the end-of-line marker.     EXAMPLE 1: import csv  # Importing the csv module # CSV file opened using relative path csv_fobj = open("emp.csv", "w")   # Writer object created wtr_obj = csv.writer(csv_fobj) # Record with field heading is written wtr_obj.writerow(["Empno", "Name", "Salary"]) # Records with data are...