#task: create the empty data structure grocery_item = {}; grocery_history = []; #Variable used to check if the while loop condition is met user_input = 'c' item_count = 1 while user_input!='q': #Accept input of the name of the grocery item purchased. print("Item name:\n") item_name = input() #Accept input of the quantity of the grocery item purchased. print("Quantity purchased:\n") quantity = input() #Accept input of the cost of the grocery item input (this is a per-item cost). print("Price per item:\n") cost = input() #Using the update function to create a dictionary entry which contains the name, number and price entered by the user. grocery_item.update({'name':item_name}) grocery_item.update({'number':int(quantity)}) grocery_item.update({'price':float(cost)}) #Add the grocery_item to the grocery_history list using the append function grocery_history.append(grocery_item) grocery_item = {} #Accept input from the user asking if they have finished entering grocery items. print("Would you like to enter another item?\n Type 'c' for continue or 'q' to quit:\n") user_input = input() # Define variable to hold grand total called 'grand_total' grand_total = 0 #Define a 'for' loop. for k in grocery_history: #Calculate the total cost for the grocery_item. item_total = k["number"]*k["price"] #Add the item_total to the grand_total grand_total=grand_total+item_total #Output the information for the grocery item to match this example: #2 apple @ $1.49 ea $2.98 print(str(k["number"])+' '+k["name"]+' @ $'+str(k["price"])+' ea $'+str(item_total)) #Set the item_total equal to 0 item_total = 0 grand_total = round(grand_total,2) #Print the grand total print("Grand total: $"+str(grand_total))