Probem Statement :
Make a Grocery List for super market shopping with name, price and quantity; if the list already contains an item then only update the price and quantity it should not append the item name again. Ask user his/her budget initially
and minus the budget after adding a new item in the list. If budgets go zero/0 then no more item could be bought and if some money left and user add item greater than budget left then inform “over price” or any other message. After the list is made any money left in the budget it should show an item within the budget from the list made.
VALIDATION is a must.
User GO with following question Enter Your budget : 500 1.Add an item 2.Exit Enter your choice : 1 Enter product : corn flour Enter quantity : 1.5 kg Enter Price : 100 Amount left : 400 1.Add an item 2.Exit Enter your choice : 1 Enter product : wheat Enter quantity : 2 kg Enter Price : 100 Amount left : 300 1.Add an item 2.Exit Enter your choice : 1 Enter product : corn flour Enter quantity : 2 kg Enter Price : 250 Amount left : 150 1.Add an item 2.Exit Enter your choice : 1 Enter product : rice Enter quantity : 5 kg Enter Price : 300 Can't Buy the product ###(because budget left is 150) 1.Add an item 2.Exit Enter your choice : 1 Enter product : xyz Enter quantity : 1 kg Enter Price : 50 Amount left : 100 1.Add an item 2.Exit Enter your choice : 2 Amount left can buy you wheat GROCERY LIST is: Product name Quantity Price corn flour 2 kg 250 wheat 2 kg 100 xyz 1 kg 50
Try to understand the above Problem statement and output explanation and try it yourself before going to the solution
Code : Python code to check the Grocery List
- Python | Combine two lists by maintaining duplicates in first list
- Python | Inserting item in sorted list maintaining order
- Python | Convert list of string to list of list
- Python | Convert list of tuples to list of list
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Replace elements in second list with index of same element in first list
- Python | Pair and combine nested list to tuple list
- Python | Convert list of string into sorted list of integer
- Python | Convert list of numerical string to list of Integers
- Python | Merge list of tuple into list by joining the strings
- Python | Merge List with common elements in a List of Lists
- Python | Find maximum length sub-list in a nested list
- Python | Sorting list of lists with similar list elements
- Python | Add list elements with a multi-list based on index
- Python | Filter list of strings based on the substring list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.