Program features:
1, start the program that allows the user to enter wages, and then print the Product List
2, allows users to purchase by product number
3, after the user selects a product, testing the balance is enough, enough to direct debit, is not enough to remind
4, may at any time withdraw, exit, print the purchase of goods and balances
your_salary = int(input("Please your salary:")) goods = [[1, "IPhone", 5900], [2, "OPPO", 3700], [3, "MI", 1000], [4, "HP COMPUTER", 2000], [5, "MAC", 10000]] favorite_goods = [] print("Number\tGoods\tPrice") for i in goods: print("%s\t%8s\t%5s"% (I [0], I [. 1], I [2 ])) Print ( " input non-numeric, and jumps end shopping payment menu " ) the while True: goods_number = INPUT ( " Please the Choose your Favorite Goods: " ) IF goods_number.isdigit (): # If goods_number digital strong turn into an int goods_number = int (goods_number) the else : BREAK IF goods_number> len (Goods): # entered number does not exist, to jump to the beginning of the cycle Print ( " IS not exist Goods. " ) the Continue favorite_goods.append (Goods [goods_number -1]) # selected product into the shopping cart list Print (Goods [-goods_number. 1] [. 1] + " has been added to the shopping cart " ) total_goods = 0 for I in favorite_goods: # statistical cart price total_goods + = i [2 ] IF total_goods> your_salary: Print ( " total merchandise purchased for% s, have exceeded your salary% S " % (total_goods, your_salary)) Print ( " have you goods cleared S% " % (favorite_goods.pop () [. 1 ])) IF favorite_goods == []: # favorite_goods list is empty, exit the program Print ( " shopping cart is empty, the program exits " ) quit (0) Print ( " Your Cart is as follows: " ) Print ( " Number The \ tGoods \ tPrice " ) for I in favorite_goods: # print cart Print ( " % S \ T% 8S \ T% 5S " % (I [0], I [. 1], I [2 ])) Print ( ' - ' *. 8 ) buy_goods = the INPUT ( "Buy you to the Sure the Do (b / B)? " ) IF buy_goods == ' b ' or buy_goods == ' B ' : # purchase of goods, and show the balance Print ( " The total price of goods purchased:% S " % (total_goods )) Print ( " your wages remaining:% S " % (your_salary- total_goods)) the else : Print ( " to cancel the purchase of the shopping cart of goods " ) Print ( " cart total price:% S " %(total_goods)) print(" Salary remaining:% S " % (your_salary))