练习
list练习
1,启动后,让用户输入工资,打印商品列表
2,允许用户根据商品编号购买商品
3,用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒
4,可随时退出,退出时,打印已购买的商品和余额
#!/usr/bin/env python3 # -*- coding:utf-8 -*- # -*- Author:Hinimix -*- goods_list = [["yerongqiu", 20], ["iphone", 5000], ["muzhibing", 30], ["ipad", 2500], ["meng", 10000]] salary = int(input("enter your salary")) select_list = [] while True: print("goods are below") for good in goods_list: print(good) selection = input("select your goods") for tmp in range(0,len(goods_list)): if goods_list[tmp][0] == selection: select_list.append(goods_list[tmp]) salary -= goods_list[tmp][1] break else: print("no this good") if salary < 0: select_list.pop() print("you had bought %s" % select_list) exit() op = input("press c to continue, q to quit") if op == 'q': print("you had bought %s" % select_list) print("money left %d" % salary) break elif op == 'c': continue else: print("wrong input")