#coding = utf-8 goods_data = (["iphone7",8000],["mac pro",12000],["bike",1000]) buyed_goods =[] def display_menu(): mes = ‘‘‘ ******购物商城系统****** 1.%s %d 2.%s %d 3.%s %d 4.退出系统 ************************ ‘‘‘%(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 = ‘‘‘ ---购物清单--- ‘‘‘ print(mes) for i in(buyed_goods): print(i) def toselect(): display_menu() selected = int(input("请选择:")) return selected yue = int(input("输入金额:")) while True: se =toselect() if(se == 1 and yue >= goods_data[0][1] ): buyed_goods.append([goods_data[0][0],goods_data[0][1]]) yue -= goods_data[0][1] print("购买商品%s成功,花费%d RMB,余额为:%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("购买商品%s成功,花费%d RMB,余额为:%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("购买商品%s成功,花费%d RMB,余额为:%d" % (goods_data[2][0], goods_data[2][1],yue)) continue else: print("余额不足!!!") showbought(buyed_goods) break
原文地址:https://www.cnblogs.com/g177w/p/8120461.html
时间: 2024-11-11 11:54:03