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

PYTHON - MYSQL CONNECTIVITY CODE

  #INSERTION OF DATA import mysql.connector mydb = mysql.connector.connect( host="localhost", user="root", passwd="root", database="school" ) print("Successfully Connected") #print(mydb) mycursor=mydb.cursor()   v1=int(input("enter ID:")) v2=input("enter name:") v3=input("enter Gender:") v4=int(input("enter age:")) sql='insert into TEACH values("%d","%s","%s","%s")'%(v1,v2,v3,v4) print(sql) mycursor.execute(sql) mydb.commit() print("record added") #MYSQL Connection code – Deletion on database SOURCE CODE: s=int(input("enter id of TEACHER to be deleted:")) r=(s,) v="delete from TEACH where id=%s" mycursor.execute(v,r) mydb.commit() print("record deleted") MYSQL Connection code – Updation on database SOURCE CODE: import mysql.connector mydb = mysql.connector.c...

REVISION IF CONSTRUCT | CLASS TEST

                                                                                     CLASS TEST 1. Write a Python program that asks the user for their age, gender, and current fitness level (beginner, intermediate, or advanced). Based on this information, suggest a suitable fitness plan using if-else statements. Requirements: Inputs : Age (integer) Gender (male/female) Fitness level (beginner/intermediate/advanced) Outputs : Recommend a fitness plan that includes: Suggested workout duration. Type of exercises (e.g., cardio, strength, flexibility). Rest days. Logic : Use if-else to determine the plan based on conditions such as: Age group (e.g., <18, 18–40, >40). Fitness leve...