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

CS - SORTING/SEARCHING ALGORITHMS

  SORTING ALGORITHMS                       SORTING ALGORITHM PDF LINK #Bubble Sort          ·        The outer loop iterates through the entire array. ·        The inner loop compares adjacent elements and swaps them if they are out of order. ·        The outer loop runs n times, and each pass moves the largest element to its correct position. arr=[3,8,5,2,1] n = len(arr) print(n) for i in range(n):  #traverse through all the elements         # Last i elements are already sorted, no need to check them         for j in range(0, n-i-1):              # Swap if the element found is greater than the next element              if arr[j] > arr[j+1]:               ...

GRADE XI - NESTED FOR LOOP

                                                         NESTED FOR LOOP 1. for var1 in range(3):      print(var1,"OUTER LOOP")          # 0 outer loop       1 outer loop      2 outer loop          for var2 in range(2):                  print(var2+1,"INNER LOOP")    #1  2 inner loop     1  2  inner loop   1 2 inner loop  2. Print the following pattern using for loop: 1  1 2  1 2 3  1 2 3 4  Sol: for r in range(1,5):   #ROWS     for c in range(1,r+1):   #COLUMNS         print(c,end=" ")     print() 3. Print the following pattern using for loop: @  @ @  @ @ @...