Question: Lists. This code emulates shopping, first the user selects items she or he wants to buy and adds them to the shopping list. Next, the





Lists. This code emulates shopping, first the user selects items she or he wants to buy and adds them to the shopping list. Next, the user selects items from the list and place them into the cart. Please read the code and answer the following five questions about it. # shopping program # create an empty list and add grocery items to the list grocery_list = 0 while True : item - input("Enter a grocery item you want to buy: ") if item break else: grocery_list.append(item) print ("Your grocery list is ", grocery_list) # remove items from the list and add them to the cart cart - n = len(grocery_list) for i in range(n): item - grocery_list.pop() input("Did you find and want to buy this " + item + "?"). upp ero if (ans 'Y'): cart.append(item) else: grocery_list.append(item) print ("Your shopping cart is ", cart) ans = Note: The question order is shuffled by default in quizzes on Canvas. I f you want to do the questions in order, then answers questions labeled as Q1 then Q2 then Q3 then 04 then 05. Problem 2 Q1. What should the user enter to terminate the while loop? O a string "n" O a string "Y" O a string "quit" O an empty string O a string "N" O a string "Y" Problem 2 Q5. If we modify the statement: item = grocery_list.pop(0) to item = grocery_list.pop() what other statement should we change to make the same program output? for i in range(n): cart.append(item) none grocery_list.append(item) Q4. If the user enters: apples bananas salt bread tomatoes pasta a S N n Y How many items in the cart are at the end of the program? 3 1 6 2 TUDICTZ Q2. If the user enters: apples bananas salt bread tomatoes pasta n n what products did she/he buy? Select all that apply. salt pasta bananas apples bread tomatoes apples bananas salt bread tomatoes pasta a
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
