首页 > 代码库 > PYTHON 购物车程序
PYTHON 购物车程序
product_list = [ (‘iphone‘,50000), (‘Mac Pro‘,9900), (‘Bike‘,8000), (‘Watch‘,160000), (‘Coffee‘,600), (‘lqgyc‘,1200) ] shopping_list = [] salary = input("请输入工资:") if salary.isdigit(): # isdigit() 方法检测字符串是否只由数字组成 salary = int(salary) while True: for index,item in enumerate(product_list): print(index,item) user_choice = input("请选择商品>>>") if user_choice.isdigit(): user_choice = int(user_choice) if user_choice < len(product_list) and user_choice >= 0: p_item = product_list[user_choice] if p_item[1] <= salary: shopping_list.append(p_item) salary -= p_item[1] print("Added %s into shopping cart,your current balar:",salary) else: print("你的余额只剩[%s]啦,无法购买"% salary) else: print("product code [%s] is not exist !" % user_choice) elif user_choice == ‘q‘: print(‘---商品列表!---‘) for p in shopping_list: print(p) print("your current balance:", salary) exit() else: print("请输入商品序列号!")
PYTHON 购物车程序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。