#coding Utf-8
#1, design a shopping cart program, prompting the user to enter wages, pay input after opening the product list, prompting the user to select the product to buy
#2, select a product, if the balance is sufficient, the purchase succeeds, and the product list is printed, otherwise the purchase fails, showing the balance
Salary=int (Input ("Please enter your salary limit:"))
goodslist=[[' Sony color TV ', 3888],[' Apple Computer ', 8999],[' wok ', 199],["Iphone6", 3888],["teacup", 77]
Changgoodlist=[]
I=1
Print ("The item you entered is as follows:")
For good in Goodslist:
Print ("%d---%s----%d"% (I,good[0],good[1])
I+=1
Flag=true
While flag:
changgoodnumber = Int (Input ("Select the item you want to buy:"))
If Changgoodnumber<=len (goodslist):
if int (salary)-goodslist[changgoodnumber-1][1]>=0:
Print ("Your purchase was%s"% (goodslist[changgoodnumber-1][0))
Changgoodlist.append (Goodslist[changgoodnumber-1][0])
Salary=salary-int (Goodslist[changgoodnumber-1][1])
Print ("Your salary balance is%d Yuan"%salary)
Else
Print ("Insufficient balance, cannot buy, program exits")
Flag=false
Else
Print ("No this item, please re-select")
A simple shopping cart written in Python