#all small code hereproduct_list= [['Iphone7', 5800], ['Coffee', 30], ['Pimple Soup', 10], ['Python Book', 99], ['Bike', 199], ['ViVo X9', 2499]]shopping_cart=[]salary= Int (Input ("Input your Salary:")) whileTrue:menu= u" "-------Good shopping---------\033[32;1m 1. Enter the serial number to buy the goods into the shopping cart 2. Enter Q Print shopping list exit \033[0m" " Print(menu) Index=0 forProductinchproduct_list:Print(index,product) Index+=1Choice= Input (">>"). Strip ()ifChoice.isdigit ():#determine whether a numberChoice =int (choice)ifChoice >= 0 andChoice < Len (product_list):#Commodity PresenceProduct = Product_list[choice]#Fetch the product ifProduct[1] <= Salary:#Judging If you can afford it.Shopping_cart.append (product)#Add to Shopping cartSalary-= product[1]#Deduct Money Print("Added Product"+ product[0] +"into shopping cart,your current balance"+Str (salary))Print("The current balance is%d Yuan"%salary)#print ("Jia ge Shi" + product[haproxy.conf] + "Yuan") Else: Print("can't afford to buy, poor force! Product Price is"+STR (product) [1]+"you're still poor ."+str (product[1]-salary) +"Money") Else: Print("product does not exist") elifChoice = ="Q": Print("----List of purchased items-----") Print("ID Product Quantity Unit price Total price") forIinchShopping_cart:Print(i)Print("your balance is:", salary)Print("------End------") Break Else: Print("no such option! ")
Python's mock shopping cart