Python practice shopping cart applet, python shopping cart Applet
1 #-*-coding: UTF-8-*-2 shp = [3 ['iphone ', 5000], 4 ['offee', 35], 5 ['shoes ', 800] 6] 7 pric_list = [] 8 e = int (raw_input ("enter account amount:") 9 while True: 10 for I, p in enumerate (shp ): 11 print I, p [0], p [1] 12 enther = raw_input ("Enter the product number to be purchased :"). strip () 13 if enther. isdigit (): 14 enther = int (enther) 15 # p_price = products [choice] [1] 16 pric = shp [enther] [1] 17 if pric <= e: 18 pric_list.append (shp [enther]) 19 e-= pric20 print "% s you purchased has been added to the shopping cart, remaining amount % s" % (shp [enther] [0], e) 21 else: 22 print "the amount is insufficient. Please reselect. remaining amount % s" % e23 elif enther = 'quit ': 24 print "List of purchased items" 25 for k, v in enumerate (pric_list): 26 print k, v27 print "remaining amount: % s" % e28 print "----- welcome again ------" 29 break
After entering the amount, purchase the product until the amount is insufficient.