#coding = Utf-8goods_data = (["Iphone7", 8000],["Mac Pro", 12000],["bike", +]) buyed_goods =[]def display_menu (): mes = "' ****** shopping mall system ****** 1.%s%d 2.%s%d 3.%s%d 4. Exit System ************************ "% (Goods_data[0][0],goods_data[0][1],goods_data[1][0],goods_data[1][1],goods_data[2][0],goods_data[2][1]) Print (MES) def showbought (buyed_goods): length = Len (buyed_goods) mes = '---shopping list---' Print (MES) for I in (buyed_goods): Print (i) def toselect (): Display_menu () selected = Int (Input ("select:")) return Selectedyu e = Int (input ("Enter Amount:")) while True:se =toselect () if (SE = = 1 and yue >= goods_data[0][1]): Buyed_goods.ap Pend ([goods_data[0][0],goods_data[0][1]]) Yue-= goods_data[0][1] Print ("The purchase of the product%s was successful, cost%d RMB, the balance is:%d"% (Goods_ Data[0][0], Goods_data[0][1],yue)) Continue if (SE ==2 and Yue >= goods_data[1][1]): buyed_goods.append ([goods_data[1][0], goods_data[1][1]]) Yue-= goods_data[1][1] Print ("The purchase of the product%s was successful, cost%d RMB, the balance is:%d"% (Goods_data[1][0], goods_data[1][1], Yue)) Continue if (SE ==3 and Yue >= goods_data[2][1]): Buyed_goods.append ([goods_data[2][0], goods_data[2][ 1]]) yue-= goods_data[2][1] Print ("The purchase of the product%s was successful, cost%d RMB, the balance is:%d"% (Goods_data[2][0], Goods_data[2][1],yue)) Continue Else:print ("Insufficient balance!!! ") Showbought (buyed_goods) break
Python tuples, lists, dictionary exercises