# This cycle will continue as long until the budget becomes integer or floating while True : try : bg = float ( input ( "Enter your budget:" )) # if the budget is integer or floating point, it will be saved # temporarily in the variable & # 39; s & # 39; s = bg except ValueError: print ( " PRINT NUMBER AS A AMOUNT " ) continue else : break # dictionary for storing goods ("name"), quantity ("quantity"), # price (& quot; price & quot;) with an empty list as values a = { "name" : [], "quant " : [], " price " : []} # convert the dictionary to a list for further updates b = list (a.values ()) # variable na value & quot; name & quot ; from the dictionary & # 39; a & # 39; na = b [ 0 ] # variable qu," quant "value from dictionary & # 39; a & # 39; qu = b [ 1 ] # variable pr value & quot; price & quot; from the dictionary & # 39; a & # 39; pr = b [ 2 ] # This loop ends when the user selects the 2.EXIT option when prompted # when trying, it will ask the user for an integer parameter (1 or 2) # if correct then continue, otherwise keep asking options while True : try : ch = int ( input ( " 1.ADD 2.EXIT Enter your choice: " )) except ValueError: print ( "ERROR: Choose only digits from the given option " ) continue else : # check budget is greater than zero and option is selected # user - 1, i.e. add element if ch = = 1 and s" 0 : # product name pn = input ( " Enter product name: " ) # enter the quantity of the product q = input ( " Enter quantity: " ) # entry price of goods p = float ( input ( "Enter price of the product:" )) if p" s: # checks if budget price is less print ( "CAN, T BUT THE PRODUCT" ) continue else : # checks if the product name is in the list if pn in na: # find the index of this product ind = na.index (pn) # remove quantity from "quantitative" product index qu.re move (qu [ind]) # remove price from the price index product pr.remove (pr [ind]) # insert the new value given user earlier qu.insert (ind, q) # insert the new value given user earlier pr.insert (ind, p) # subtract the price from the budget and assign # this is to & # 39; s & # 39; sum (pr) because pr = [100, 200] if # budget is 500 then s = bg-sum (pr) = 200 # after updating for the same product from index 0 # pr = [200, 200], so s = 100 s = bg - sum (pr) print ( "amount left" , s) else : # add value to & quot; name & quot;, & quot; quantity & quot;, & quot; price & quot; na.append (pn) # as na = b [0] will add all values to # list eg: & quot; name & quot ;: [& quot; pic & quot;] qu.append (q) # same for quantity and price pr.append (p) # after adding a new value, the amount in the price # how it will be calculated s = bg - sum (pr) print ( "amount left" , s) # if the budget is reset to zero, output "NO BUDGET" elif s " = 0 : print ( "NO BUDGET" ) else : break # will print the amount left in the variable & # 39; s & # 39; print ( "Amount left: Rs." , s) # if the remaining amount is equal to any amount in the price list if s in pr: # then print the name of the product you can buy print ( "Amount left can buy you a" , na [pr.index (s)]) print ( "GROCERY LIST" ) # print the final shopping list for i in range ( len (na)): print (na [i], qu [i], pr [i]) |