Python Program- Grocery Shopping
In this program, we will learn to create a python program for grocery shopping.
Through this program, available items with price would be displayed to the user and the option to add items and corresponding quantities would be given until the user opts not to do further shopping. Detailed requirements can be seen in the section - How It Should Work . There are paths associated when a user enters no for shopping or enters an item that does not exist. Items and prices are saved in a separate text file so that it can be changed without changing code and can contain large data too. Hence we need to a reading of a text file through the code itself.
If you wish to learn the concepts and see the detailed steps to arrive at the solution, refer to my video on youtube
Python reading from a text file, dictionaries, nested dictionaries, lists, while loop, inputs, if-else, for loop, type conversion, f-string
How It Should Work
Create a text file(available_grocery_items.txt) that contains menu items and prices. Something like below:
Item UnitPrice Soap 2 Toothbrush 2.3 Apple 1.5 Kiwi 3.4 Spinach 1.2 Cookie-Jar 10 Water-Bottle 2 Juice 4 Milk 3 Coffee 7 Chips 2 Eggs 4.5
The code first, display a welcome message to a user with a username taken from the input method
Read through the file and save item keys and price values in a dictionary
Display items with the corresponding price to the user
Ask if the user wishes to continue with shopping
Once the user wishes to continue, give the user option to add items one by one along with the corresponding quantity
Also, the user should be presented an option to add an item, until the user does not wish to add more items
Finally,present a bill summary to user with item, quantity, subtotal and final total bill