Want to take out two ordinary world , But with for Loop traversal can only take out one , And I want to take out two books of liucixin
print('************** The book management system **************')library = [{
'name':' Trisomy ','author':' liu ','price':24,'number':5}, {
'name':' Wandering the earth ','author':' liu ','price':26,'number':5} ,{
'name':' Ordinary world ','author':' Lu yao ','price':108,'number':5}, {
'name':' Ordinary world ','author':' Luyao ','price':108,'number':5} ,{
'name':' Alive ','author':' Yuhua ','price':20,'number':5}]name_list = []author_list = []for i in library: name_list.append(i.get('name')) author_list.append(i.get('author'))print(name_list)print(author_list)while 1: print('1. Borrow books \n2. Return books \n3. Inquire about \n4. Library \n5. sign out ') choice = int(input(' Please select the function :')) if choice == 1: i_name = input(' Please enter the book you want to borrow :') n_number = name_list.count(i_name) for i in range(0,n_number): for book in library: if book.get('name') == i_name: print(' The relevant information in this book is :\n Title :{}\t author :{}\t Price :{} element \t Inventory :{} Ben '.format(book.get('name'), book.get('author'), book.get('price'),book.get('number'))) break else: print(' The book is not included in the library ')
You want to realize the selection of books according to the book title and the selection of books according to the author's name , And take them all out
Then put your code if The branch break Take it out