‘‘‘ 1. 输入用户的工资 2.根据用户的工工资进行选择性的购买 3.最后打印用户购买的产品和用户的余额‘‘‘product_list = [ (‘iphone‘,5000),(‘mar pro‘,8000),(‘ipad‘,7000),(‘iphone‘,15000)]shopping_list = list()salary = input(‘请输入您的工资:‘)if salary.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 = salary - p_item[1] print(‘您的余额是{}‘.format(salary)) elif p_item[1] > salary: print(‘您的余额不多,无法进行交易‘) else: print(‘商品不存在‘) elif user_choice == ‘q‘: print(‘-----shopping list-------‘) for p in shopping_list: print(p) print(‘您的余额是{}‘.format(salary)) exit() else: print(‘输入有误‘)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。