博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 购物车
阅读量:7040 次
发布时间:2019-06-28

本文共 1572 字,大约阅读时间需要 5 分钟。

goods_list = [    {
'name': '苹果', 'price': '10'}, {
'name': '香蕉', 'price': '15'}, {
'name': '菠萝', 'price': '20'}, {
'name': '西瓜', 'price': '25'}, {
'name': '葡萄', 'price': '30'},]shopping_car = {}print("欢迎光临小粉嫩水果店!")money = input("请拿出您的银子:")if money.isdigit() and int(money) > 0: flag = True while flag: for i, k in enumerate(goods_list): print('序号{}, 商品{}, 价格{}'.format(i, k['name'], k['price'])) choose = input("请输入您选择的序号:") if choose.isdigit() and int(choose) < len(goods_list): num = input("请输入您要购买商品的个数:") if num.isdigit(): if int(money) > int(goods_list[int(choose)]['price']) * int(num): money = int(money) - int(goods_list[int(choose)]['price']) * int(num) if goods_list[int(choose)]['name'] in shopping_car: shopping_car[goods_list[int(choose)]['name']] = shopping_car[goods_list[int(choose)]['name']] + int(num) else: shopping_car[goods_list[int(choose)]['name']] = int(num) print("购物车中的商品有{}, 您的余额为{}".format(shopping_car, money)) print("如果您想离开请按Q或q,欢迎下次光临!") else: print("穷鬼,滚去敲代码赚钱!") break else: print("请输入数字,谢谢!") elif choose.upper() == "Q": flag = False print("您当前的购物车为{},余额为{}".format(shopping_car, money)) else: print("傻逼,输入数字!!!")

 

转载于:https://www.cnblogs.com/-1206-/p/9484526.html

你可能感兴趣的文章
ImageNet && 医学图像的识别
查看>>
HBase编程 API入门系列之delete(客户端而言)(3)
查看>>
Cocos2dx使用wxsqlite开源加密SQLite3数据库
查看>>
JMeter学习-内存溢出解决方法
查看>>
磨刀不误砍柴工——VS生成事件
查看>>
XE7 update1
查看>>
Omi 树组件 omi-tree 编写指南
查看>>
Kubernetes 准入控制 Admission Controller 介绍
查看>>
Kotlin协程快速入门
查看>>
AudioKit 入门教程
查看>>
日吞吐万亿,腾讯云时序数据库CTSDB解密
查看>>
02、Python 系列之 Python 环境搭建
查看>>
有米iOS恶意SDK分析
查看>>
基于Android5.0的Camera Framework源码分析 (二)
查看>>
你可能会用到的Android Studio快捷键
查看>>
iOS strong weak unowned引用
查看>>
JS每日一题: Call,Apply,Bind的使用与区别,如何实现一个bind?
查看>>
数据结构_Swift实现栈,队列,链表
查看>>
RAC(ReactiveCocoa)使用方法(一)
查看>>
大数据开发工程师学习路线分享
查看>>