标签:pen 用户 苹果 tin col 苹果手机 半成品 for int
‘‘‘ 需求: 1.启动程序后,让用户输入工资,然后打印商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 4.可随时退出,推出时,打印已购买商品和余额 ‘‘‘ commodity = [[1,"苹果手机",13800],[2,"oppo手机",3800],[3,"皮带手机",800],[4,"杂牌手机",300],[5,"坚果手机",2800],[6,"联想手机",6600],[7,"华为手机",8800]] money = 15200 haveBought = [] while True: print("编号\t\t名称\t\t\t\t价格") for Commodity in commodity: print("%d\t\t\t%s\t\t\t%d" % (Commodity[0], Commodity[1], Commodity[2])) UserInput = int(input("请输入商品编号:")) UserInp = UserInput - 1 if money > commodity[UserInp][2]: print(commodity[UserInp]) haveBought.append(commodity[UserInp]) print("您已购买了%s 商品" % haveBought) break else: print("您目前的余额不足以购买%s"% (commodity[UserInp][1])) userI = input("您是否要前往充值?是,请输入Y") if userI == ‘Y‘ : break else: continue
标签:pen 用户 苹果 tin col 苹果手机 半成品 for int
原文地址:https://www.cnblogs.com/ArtisticMonk/p/8907153.html