Need Help ?

Home / Expert Answers / Other / can-t-use-break-my-grocery-list-grocery-list-py-you-ve-been-hired-by-a-local-grocery-store-to-create

(Answered): Can't use Break. My Grocery List (grocery_list.py) You've been hired by a local grocery store to cre ...




My Grocery List (grocery_list.py) Youve been hired by a local grocery store to create a program that they can make availablefrom the list, otherwise issue a message <item> is not on your list! if the item isnt on the grocery list. 7. read_groceryYour program should match the provided sample runs below: My Grocery List Please select from the following options: 1. View G
Can't use Break.
My Grocery List (grocery_list.py) You've been hired by a local grocery store to create a program that they can make available to their customers. The program, called My Grocery List, will allow users to keep track of their grocery list. It will allow the user to view their grocery list, as well as add items and remove items from the list. You will store the list of groceries in a text file (groceries.txt) so the items remain persistent between program uses. When the program starts, it will read in the contents of the text file and store the items in a Python list. Since this data type (lists) allows you to store multiple elements within a single object, it makes for an appropriate choice to use in the implementation of this program. During the program run, all operations will be performed on the list, only writing the items back to the text file at the end of the program run (i.e. when the user selects to quit). Lists are mutable, thus well-designed to handle adding and removing elements dynamically. Your program should have the following functions: 1. main: Begins program execution: Calls read_grocery_list_file to get a list of the gro- ceries currently stored in the text file. Then, calls get_menu_option to obtain the user's menu selection (an integer). Use that value to call the function associated with the user's choice (e-g if the user entered 1, call the view_grocery_list function). Make sure to account for each of the menu items and route the program to the indicated function. Your program should return back to this menu after each task has been completed to allow the user to select another option (eg if the user added a new item to their list in option 2, they can then select option 1 to view their updated list). 2. get_menu_option: no parameters. Calls display_title to display the program title. Presents the user with a menu of options to select from (see sample runs). Prompts the user to enter an integer that is mapped to their menu selection (eg "1. View Grocery List"). Make sure to validate user input. Return the user's choice as an integer. 3. view_grocery_list: One parameter variable, a list containing the grocery items Displays all items in a numbered grocery list, or the message "Your grocery list is currently empty." 4. display_title: displays the program title, "My Grocery List", with dashes above and below the text (see sample runs). No parameters or return values. 5. add_item: One parameter variable, a list containing the grocery items. Prompts the user, "Enter the item to add to your grocery list:". Add that item to the list, otherwise issue a message"<item> is already on your list" if the item is already on the grocery list. 6. remove_item: One parameter variable, a list containing the grocery items. Prompts the user, "Enter the item to remove from your grocery list:" Remove that item from the list, otherwise issue a message "<item> is not on your list!" if the item isn't on the grocery list. 7. read_grocery_list_file: No parameters. Opens groceries.txt, a text file that contains grocery items stored one per line (what happens if the text file doesn't exist?). Reads in the entire contents of the text file and stores each item as an element within a list. Returns that list. 8. write_grocery_list_file: One parameter variable, a list containing the grocery items. Opens the groceries.txt text file and writes the grocery list to that file. Each item should be on its own line in the file. No return value. 9. program_exit: One parameter variable, a list containing the grocery items. Prompts the user, Are you sure you want to exit? (y/n)". Validate user choice. If user confirms (1.e. enters "Y"), issue the message "Thank you for using My Grocery List!", then call the write_grocery_list_file function and pass the list of grocery items to it. If the user selects "n", return to the options menu. Hints: 1. Lists can be very useful in verifying that the user has selected one of the possible menu options: choice = input(">>> ") if choice not in ["a", "b", "C", "d"]: print("Invalid option.") 2. Check out the enumerate function to make quick work of associating numbers with items when printing a list: my_list = ["a", "b", "c", "d"] for num, item in enumerate (my_list): print (num, item) Produces: 0 ? 1 b 2 C 3 d Your program should match the provided sample runs below: My Grocery List Please select from the following options: 1. View Grocery List 2. Add Item to Grocery List 3. Remove Item from Grocery List 4. Quit >>> 1 You have the following items on your grocery list: 1. milk 2. eggs 3. cheese 4. berries 5. apples My Grocery List Please select from the following options: 1. View Grocery List 2. Add Item to Grocery List 3. Remove Item from Grocery List 4. Quit >>> 2 Enter the item to add to your grocery list: >>> orange juice orange juice was added to your list! My Grocery List Please select from the following options:


We have an Answer from Expert

View Expert Answer

Expert Answer


Answer to My Grocery List (grocery_list.py) You've been hired by a local grocery store to create a program that they can make avai...
We have an Answer from Expert

Buy This Answer $4

Place Order