Python - Maintaining Grocery List: Probem Statement
Python - Maintaining Grocery List: Probem Statement
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.
1.Add an item
2.Exit
Enter your choice : 1
1.Add an item
2.Exit
Enter your choice : 1
1.Add an item
2.Exit
Enter your choice : 1
1.Add an item
2.Exit
Enter your choice : 2
# This loop terminates when user select 2.EXIT option when asked
# in try it will ask user for an option as an integer (1 or 2)
# if correct then proceed else continue asking options
while True:
try:
ch = int(input("1.ADD\n2.EXIT\nEnter your choice : "))
except ValueError:
print("\nERROR: Choose only digits from the given option")
continue
else:
# check the budget is greater than zero and option selected
# by user is 1 i.e. to add an item
if ch == 1 and s>0:
if p>s:
# checks if price is less than budget
print("\nCAN, T BUT THE PRODUCT")
continue
else:
# checks if product name already in list
if pn in na:
# find the index of that product
ind = na.index(pn)
print("\namount left", s)
else:
# append value of in "name", "quantity", "price"
na.append(pn)
print("\namount left", s)
print("\n\n\nGROCERY LIST")