3.购物车
2017-08-11 10:44
176 查看
product_list = [ ('iphone', 5800), ('Mac Pro', 9800), ('Bike', 800), ('Watch', 10600), ('Cofee', 31), ('python', 120) ] shopping_list = [] def panduan(string): s = str(string) if s.count('.') == 1: sl = s.split('.') left = sl[0] right = sl[1] if left.isdigit() & right.isdigit(): return True else: return False elif s.isdigit(): return True else: return False salary = input("Input your salary:") if panduan(salary): salary = float(salary) while True: for index, item in enumerate(product_list): print(index, item) user_choose = input("请输入商品编号:") if user_choose.isdigit(): user_choose = int(user_choose) if user_choose < len(product_list) and user_choose > 0: s = product_list[user_choose] if s[1] <= salary: shopping_list.append(s) salary -= s[1] print('added %s into your shopping cart ,your balance is \033[31;1m%s\033[0m' % (s[0], salary)) else: print('your salary can not affrond') else: print('您输入的商品编号不存在...') elif user_choose == 'q': print('----------shopping list-------------') for i in shopping_list: print(i) print('余额:', salary) print('------------------------------------') exit() else: print('无效编号!!!')
相关文章推荐
- JSP类似购物车根据后台数据自动生成一行商品,点击按钮实现数量价格自动增加
- ptython之购物车
- Android购物车的实现(升级版 仿淘宝)
- python购物车----运维开发初学
- ecshop二次开发 购物车添加备注信息
- 用PHP开发购物车网站(第二篇):PDO数据库
- 做个毕设也不容易之购物车模块遇到java.lang.IllegalArgumentException
- 使用Python的Django框架结合jQuery实现AJAX购物车页面
- php 实现购物车
- PHP 购物车 session(非框架)
- 用PHP开发购物车网站(第三篇):零碎知识(1)
- Ecshop购物车Ajax数量添加减少
- android 仿饿了么购物车
- Android仿外卖购物车功能
- 加入购物车 动画效果
- 源码推荐(0623):最简洁的购物车通用模板,咸鱼APP-视频动画版新特性
- PHP电商购物车(一:建立数据表)
- 从沈阳超市的购物车谈起
- 由浅入深理解Android中的回调机制(二)【实现简易购物车功能】
- [置顶] Java Web学习(33): 阶段小项目使用MVC模型实现购物车效果