标签:lex 运行程序 number 商品 hone enter NPU user 程序
#!/usr/bin/env python # -*- coding: utf-8 -*- # Author:DaShuang.Gu ‘‘‘要求: 买家 1.商品信息存在文件里 2.已购商品,余额记录。第一次启动程序时需要记录工资,第二次启动程序时显示出上次余额 3.允许用户根据商品编号购买商品 4.用户选择商品后,检测是否够,够就直接扣款,不够就提醒 5.可随时退出,退出时,打印移购买商品和余额 商家入口: 可以添加商品,修改商品价格,运行程序输出第一级菜单 ‘‘‘ product_list = [ (‘Iphone‘,5800), (‘Mac Pro‘,9800), (‘Bike‘,800), (‘Watch‘,10600), (‘Coffee‘,31), (‘Alex Python‘,120), ] shopping_list = [] user_salary = input("请输入你的薪水:") if user_salary.isdigit(): user_salary = int(user_salary) while True: #打印出商品信息 print(‘Product list‘.center(30, ‘*‘)) for index,item in enumerate(product_list): print(index,item) #break shopping_number = input("输出你要买的商品编号:") if shopping_number.isdigit(): shopping_number = int(shopping_number) if shopping_number < len(product_list) and shopping_number >= 0: p_item = product_list[shopping_number] if user_salary >= p_item[1]: shopping_list.append(p_item) user_salary -= p_item[1] print("商品%s加入到购物车,还有余额%s" % (p_item, user_salary)) else: print(‘余额不足%s‘ % user_salary) else: print(‘输入的产品编号不存在‘) elif shopping_number == ‘q‘: print(‘shopping list‘.center(30,‘*‘)) for i in shopping_list: print(i) print("还乘余额%s"%user_salary) exit()
标签:lex 运行程序 number 商品 hone enter NPU user 程序
原文地址:https://www.cnblogs.com/Dashuang/p/9451945.html