Python Dictionary

Asked 2 years ago, Updated 2 years ago, 14 views

/ For search, you can search if the starting word is the same even if you type only one title For example, when the title of the book is "Python was the easiest," the search word is "Python," Search for words such as "most", "easy", and you'll get the results If you put in the value, it'll print out even if you put in words that aren't in the dictionary... I've been watching this for 4 hours Help me

while True: Book_dic={} num=int(input()'Select action\n1.Book registration\n2.Book search\n3.Book alignment\n4.Book deletion'))

if num==1:
        print ('Enter Book Information')
        #Book=('1.Name\n2.ISBN\n3.Author\n4.Company\n5.Price')
        #Book_dic={}
        Title=input ('name')
        ISBN=input('ISBN')
        author=input ('author')
        company=input ("company")
        price=input ('price')
        Book_dic={'Title':Title,'ISBN':ISBN,'author':author,'company':company,'price':price}
        print(Book_dic) 
if num==2:
  Book_dic={'Title':Title,'ISBN':ISBN,'author':author,'company':company,'price':price}
    print ('Select the book you want to search')
    find=input('1.Name:')

: ')

python

2022-09-22 08:40

1 Answers

Book_list = []

while True:
    num = int(input('\n\n) Select action\n1.Register books\n2.Search books\n3.Sort books\n4.Delete books\n'))

    if num==1:
        print ('Enter Book Information')
        Title=input('name:')
        ISBN=input('ISBN : ')
        author=input('Author :')
        company=input('Company :')
        price=input('price:')
        Book_dic={'Title':Title,'ISBN':ISBN,'author':author,'company':company,'price':price}
        Book_list.append(Book_dic) #Add its dictionary to Book_list
        print(Book_dic)
    elif num==2:
        print('Select the book you want to search for\n')
        book_name=input('1.Name:')
        For i in Book_list: Importing dictionaries one by one from #Book_list
            title_words = i.get('Title').split()
     #Separate the imported dictionary's title based on the space and save each word in the list // Add print(title_words) if you want to know how the title_words are stored.

            For j title_words: Gets the words in the #title_words list one by one
                If book_name == j: #If the title of the book you entered exists in the list, complete the corresponding dictionary information
                    print(i)

Is this how you wanted it to be?


2022-09-22 08:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.