(1)   输入自己所有的钱。
(2) 展示商品的序号,名称及其价格。
(3) 输入要买商品的序号。
(4) 输入要买商品的数量。
(5) 购物车中显示购买的水果名称及其对应的数量和剩余钱。
(6) 如果序号输入有误就提示用户重新输入。
(7) 如果钱不够了提示用户钱不够,并且退出程序。
# 本钱
cart = {}
money_input = input("请输入您所拥有的金额:")
if money_input.isdigit():
money = int(money_input)
if money > 1000:
print("土豪你好!请选择水果:")
if money < 1:
print("不用看了,你娃什么也买不起,走吧!")
# 商品展示 product_list = [{'name': '香蕉', 'price': 3},
{'name': '苹果', 'price': 2.5},
{'name': '梨', 'price': 5},
{'name': '橘子', 'price': 4},
{'name': '柚子', 'price': 1.5}]
for a, dict in enumerate(product_list):
print('序号:{},名称:{},单价:{}'.format(a, dict['name'], dict['price']))
# 选择商品
while 1:
index_input = input('请输入序号:');
if index_input.isdigit():
index = int(index_input)
if index >= 0 and index <= len(product_list):
weight_input = input("请输入重量:")
if weight_input.isdigit():
weight = int(weight_input)
price = product_list[index - 1]['price']
total_money = price * weight
if total_money <= money:
product_name = product_list[index - 1]['name']
had = cart.get('product_name')
if had:
has = cart[product_name]
cart = has + weight
print(cart)
else:
cart[product_name] = weight
print(cart)
money = money - total_money
print("找您零钱:", money)
else:
print("您的余额不足,小老弟!")
break
else:
print("输入重量有误!")
else:
print("序号超出范围!")
else:
print("求求你输入正确的序号!") else:
print("请输入数字:")

最新文章

  1. python-基本数据类型
  2. Android 自定义Adapter 但listview 只显示第一条数据
  3. 解决eclipseMavne的web项目debug时没有源码
  4. 李洪强漫谈iOS开发[C语言-048]-打印平方表
  5. 用nifi把hdfs数据导到hive
  6. MySQL的replace函数的用法
  7. MFC VC6++学习笔记
  8. POJ1611-The Suspects-ACM
  9. numpy中的matrix矩阵处理
  10. python 小练习之生成手机号码
  11. ;(function(){})()这种写法分号的作用 todomvc
  12. java处理图片--图片的缩放,旋转和马赛克化
  13. BZOJ 5261 Rhyme
  14. Archlinux软件包管理pacman基本使用说明
  15. webpack简单修改版本号(单页面)
  16. bzoj千题计划205:bzoj1966: [Ahoi2005]VIRUS 病毒检测
  17. C# 获取Image图片格式
  18. ZT JAVA WeakReference
  19. 勒让德定理---阶乘中素因子p的指数
  20. js 拼接字符串时,本来想要’#1′ ,返回的却是’#01′

热门文章

  1. SpringMVC——映射请求参数
  2. hdu 1556 Color the ball (线段树做法)
  3. 当鼠标悬停在链接上,或者点击过的链接,颜色会被设置为 #2a6496。同时,会呈现一条下划线。点击过的链接,会呈现一个颜色码为 #333 的细的虚线轮廓。另一条规则是设置轮廓为 5 像素宽,且对于基于 webkit 浏览器有一个 -webkit-focus-ring-color 的浏览器扩展。轮廓偏移设置为 -2 像素
  4. Linux下安装Pcntl PHP扩展
  5. css总结10:父标签没有定义高度,盒子异常移动
  6. C# Socket通信改进记录
  7. webform Response的一些成员
  8. JS判断键盘是否按的回车键并触发指定按钮点击操作
  9. [.net 多线程]SpinWait
  10. PHP获取对象的纯数字属性