Question: Given Code: In this assignment, you will be completing a program that helps user place an order for items from a Grocery store. You are




Given Code:

In this assignment, you will be completing a program that helps user place an order for items from a Grocery store. You are given a partially written program that holds a master list of items available at the grocery store, repeatedly prompts the user for the id and count of the item user wants to add to the order, until user enters 'n' when prompted to continue. See the sample runs below. Specifically, download and open the file called grocerylist.py. It has partially written code. Please complete the program: Implement displayMasterList - a function that prints the masterList in a tabular form. Implement calculateTotalPrice - a function that calculates the total price of the order so far, based on the masterList Complete the implementation of main function: This function holds the masterList as a dictionary of dictionaries where key is a string representing the ld of the item available in the store and the value is a dictionary with fields for name, price per unit and count for that item so far. Add the code inside the while-loop that o prompts the user for item id and count of the item to add to the order (note ID is a string and count is an integer), O updates the count of that item in the masterList. If user enters the same id again, the count should be updated correctly by adding to the existing count. See sample run 2 below. Sample Run 1: Valid input Le Python 3.6.3 Shell File Edit Shell Debug Options Window Help IWDIQ.. viuuL I LLULLIUY YLUULILE 12U003 yiunila 11UUL 2017 ye .PY Welcome to BC Groceries Count 0 Id 1001: 1002: 1003: 1004: 1005: Name Price Soda 2.99 Bread 2.49 Eggs 3.3 Cookies 4.25 Milk 4.99 0 0 0 0 Enter the Id of item to add: 1001 Enter the count of Soda: 2 Id Name Price Count 1001: Soda 2.99 2 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 0 1005: Milk 4.99 0 Total price so far: 5.98 Order more items? (y) y Enter the Id of item to add: 1003 Enter the count of Eggs: 2 Id Name Price Count 1001 : Soda 2.99 2 1002: Bread 2.49 0 1003: Eggs 3.3 2 1004: Cookies 4.25 0 1005: Milk 4.99 0 Total price so far: 12.58 Order more items? (y) n Goodbye! Ln: 364 Col: 4 Sample run 2: Repeated item id L Python 3.6.3 Shell File Edit Shell Debug Options Window Help 1005: Milk 4.99 Enter the Id of item to add: 1004 Enter the count of cookies: 2 Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 2 1005: Milk 4.99 0 Total price so far: 8.5 Order more items? (y) y Enter the Id of item to add: 1005 Enter the count of Milk: 1 Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 2 1005: Milk 4.99 1 Total price so far: 13.49 Order more items? (y) y Enter the Id of item to add: 1004 Enter the count of Cookies: 1 Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 3 1005: Milk 4.99 1 Total price so far: 17.740000000000002 Order more items? (y) n Ln: 438 Col: 4 - Sample run 3: Invalid input Le Python 3.6.3 Shell File Edit Shell Debug Options Window Help 1005: Milk 4.99 0 Enter the Id of item to add: 1010 Invalid ItemId. Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 0 1005: Milk 4.99 0 Total price so far: 0.0 Order more items? (y) y Enter the Id of item to add: 1004 Enter the count of cookies: two Please enter an integer count Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 0 1005: Milk 4.99 0 Total price so far: 0.0 Order more items? (y) y Enter the Id of item to add: 1004 Enter the count of Cookies: 1 Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 1 1005: Milk 4.99 0 Total price so far: 4.25 Order more items? (v) n Ln: 327 Col: 4 ########################################################################### # Grocery Items ordering system # Complete the implementation by implementing displayMasterlist, calculateTotalPrice # and completing the main function. ############################################################################ def displayMasterList (masterlist): "Displays the masterList in tabular form!!! ## Add implementation pass def calculateTotalPrice (masterlist): ## Add implementation "IT Function to calculate and return the total price of the current Order based on the masterList = sum of priceperitem*count for all items pass def main(): sep = "_"*80 print("Welcome to BC Groceries") print(sep) # Dictionary to hold current order. Keys are strings representing itemIDs, # values are dictionaries with fields name, pricePerUnit and count masterList = {"ID001": {"name": "Soda", "pricePerUnit": 2.99,"count":0}, "ID002": {"name": "Bread", "pricePerUnit": 2.49, "count":0}, IDO03": {"name": "Eggs", "pricePerUnit": 3.30, "cour 0}, "IDO04": {"name": "Cookies", "pricePerUnit": 4.25, "count":0}, "ID005": {"name": "Milk", "pricePerUnit": 4.99, "count": 0}} displayMasterlist(masterlist) ans = 'y' while (ans == 'y'): # # Add implementation # prompt the user to enter ID and count of the item # update count in the masterlist for this item, adding to # the existing count when item ID is repeated in the order. See sample run 2 # # Add error handling to take care of # invalid itemID, # non-integer count, # See Sample run 3 print(sep) displayMasterList(masterList) totalPrice = calculateTotalPrice (masterlist) print("Total price so far: ", totalPrice) print(sep) ans = input("Order more items? (y) ").lower() print("Goodbye!") if (_name_- == "__main__"): main() In this assignment, you will be completing a program that helps user place an order for items from a Grocery store. You are given a partially written program that holds a master list of items available at the grocery store, repeatedly prompts the user for the id and count of the item user wants to add to the order, until user enters 'n' when prompted to continue. See the sample runs below. Specifically, download and open the file called grocerylist.py. It has partially written code. Please complete the program: Implement displayMasterList - a function that prints the masterList in a tabular form. Implement calculateTotalPrice - a function that calculates the total price of the order so far, based on the masterList Complete the implementation of main function: This function holds the masterList as a dictionary of dictionaries where key is a string representing the ld of the item available in the store and the value is a dictionary with fields for name, price per unit and count for that item so far. Add the code inside the while-loop that o prompts the user for item id and count of the item to add to the order (note ID is a string and count is an integer), O updates the count of that item in the masterList. If user enters the same id again, the count should be updated correctly by adding to the existing count. See sample run 2 below. Sample Run 1: Valid input Le Python 3.6.3 Shell File Edit Shell Debug Options Window Help IWDIQ.. viuuL I LLULLIUY YLUULILE 12U003 yiunila 11UUL 2017 ye .PY Welcome to BC Groceries Count 0 Id 1001: 1002: 1003: 1004: 1005: Name Price Soda 2.99 Bread 2.49 Eggs 3.3 Cookies 4.25 Milk 4.99 0 0 0 0 Enter the Id of item to add: 1001 Enter the count of Soda: 2 Id Name Price Count 1001: Soda 2.99 2 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 0 1005: Milk 4.99 0 Total price so far: 5.98 Order more items? (y) y Enter the Id of item to add: 1003 Enter the count of Eggs: 2 Id Name Price Count 1001 : Soda 2.99 2 1002: Bread 2.49 0 1003: Eggs 3.3 2 1004: Cookies 4.25 0 1005: Milk 4.99 0 Total price so far: 12.58 Order more items? (y) n Goodbye! Ln: 364 Col: 4 Sample run 2: Repeated item id L Python 3.6.3 Shell File Edit Shell Debug Options Window Help 1005: Milk 4.99 Enter the Id of item to add: 1004 Enter the count of cookies: 2 Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 2 1005: Milk 4.99 0 Total price so far: 8.5 Order more items? (y) y Enter the Id of item to add: 1005 Enter the count of Milk: 1 Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 2 1005: Milk 4.99 1 Total price so far: 13.49 Order more items? (y) y Enter the Id of item to add: 1004 Enter the count of Cookies: 1 Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 3 1005: Milk 4.99 1 Total price so far: 17.740000000000002 Order more items? (y) n Ln: 438 Col: 4 - Sample run 3: Invalid input Le Python 3.6.3 Shell File Edit Shell Debug Options Window Help 1005: Milk 4.99 0 Enter the Id of item to add: 1010 Invalid ItemId. Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 0 1005: Milk 4.99 0 Total price so far: 0.0 Order more items? (y) y Enter the Id of item to add: 1004 Enter the count of cookies: two Please enter an integer count Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 0 1005: Milk 4.99 0 Total price so far: 0.0 Order more items? (y) y Enter the Id of item to add: 1004 Enter the count of Cookies: 1 Id Name Price Count 1001: Soda 2.99 0 1002: Bread 2.49 0 1003: Eggs 3.3 0 1004: Cookies 4.25 1 1005: Milk 4.99 0 Total price so far: 4.25 Order more items? (v) n Ln: 327 Col: 4 ########################################################################### # Grocery Items ordering system # Complete the implementation by implementing displayMasterlist, calculateTotalPrice # and completing the main function. ############################################################################ def displayMasterList (masterlist): "Displays the masterList in tabular form!!! ## Add implementation pass def calculateTotalPrice (masterlist): ## Add implementation "IT Function to calculate and return the total price of the current Order based on the masterList = sum of priceperitem*count for all items pass def main(): sep = "_"*80 print("Welcome to BC Groceries") print(sep) # Dictionary to hold current order. Keys are strings representing itemIDs, # values are dictionaries with fields name, pricePerUnit and count masterList = {"ID001": {"name": "Soda", "pricePerUnit": 2.99,"count":0}, "ID002": {"name": "Bread", "pricePerUnit": 2.49, "count":0}, IDO03": {"name": "Eggs", "pricePerUnit": 3.30, "cour 0}, "IDO04": {"name": "Cookies", "pricePerUnit": 4.25, "count":0}, "ID005": {"name": "Milk", "pricePerUnit": 4.99, "count": 0}} displayMasterlist(masterlist) ans = 'y' while (ans == 'y'): # # Add implementation # prompt the user to enter ID and count of the item # update count in the masterlist for this item, adding to # the existing count when item ID is repeated in the order. See sample run 2 # # Add error handling to take care of # invalid itemID, # non-integer count, # See Sample run 3 print(sep) displayMasterList(masterList) totalPrice = calculateTotalPrice (masterlist) print("Total price so far: ", totalPrice) print(sep) ans = input("Order more items? (y) ").lower() print("Goodbye!") if (_name_- == "__main__"): main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
