Question text Case study: A small online bookstore wants to manage customer orders efficiently. Each customer can select up to three books from the available titles. The system should keep track of the customer names and the list of books they have ordered. The bookstore requires a Python program that can record customer names along with their selected books, ensure that each customer cannot order more than three books, and automatically remove any duplicate books in a customer’s order using a set. The program should also display each customer’s name together with the books they have ordered, and count and display the total number of books ordered by all customers. Sample Output: Alice ordered {'Book A', 'Book B'}Bob ordered {'Book A', 'Book B', 'Book C'}Charlie ordered {'Book C'}Total books ordered: 6 Question: Complete the Python code below by filling in the missing statements in 10 blanks so that the system works as described above. Each blank is worth 1 mark. # Step 1: Initialize lists for customer names and their orderscustomers = []orders = [] # Step 2: Function to add a customer orderdef add_order(customer_name, book_list): Answer 1 Question 27[input] book_set = Answer 2 Question 27[input] # Remove duplicates customers.Answer 3 Question 27[input] orders.Answer 4 Question 27[input] else: print(customer_name, "cannot order more than 3 books") # Step 3: Function to display all ordersAnswer 5 Question 27[input] Answer 6 Question 27[input] print(Answer 7 Question 27[input], "ordered", Answer 8 Question 27[input]) # Step 4: Function to count total books ordereddef total_books(): count = 0 Answer 9 Question 27[input] count += len(book_set) Answer 10 Question 27[input] # Step 5: Example usageadd_order("Alice", ["Book A", "Book B"])add_order("Bob", ["Book B", "Book C", "Book A"])add_order("Charlie", ["Book C", "Book C"]) # Duplicate book display_orders()print("Total books ordered:", total_books())多项填空题

登录即可查看完整答案
我们收录了全球超50000道真实原题与详细解析,现在登录,立即获得答案。
类似问题
Given the list of dictionaries shown below my_dict_lst = [ {'Name': 'John Smith', 'Courses': ['MGMT1001', 'ACCT2050', 'MKTG3001']}, {'Name': 'Jane Doe', 'Courses': ['MGMT1001', 'ACCT2050', 'MKTG3001', 'FINA3001']}, {'Name': 'Jenny Green', 'Courses': ['MGMT1001', 'ACCT2050']} ] what is the correct way of accessing the accounting course ACCT2050 Jane is taking?
Which of the following lists contains three primary data structures in Python?
What was the world's first widely adopted biodiversity policy?
The aim of the Paris Agreement is to ensure that the earth’s preindustrial temperature is not exceeded by more than º Celsius.
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!