zoukankan      html  css  js  c++  java
  • python 练习购物车小程序

     1 # -*- coding:utf-8 -*-
     2 shp = [
     3     ['iphone',5000],
     4     ['offee',35],
     5     ['shoes',800]
     6 ]
     7 pric_list = []
     8 e = int(raw_input("请输入账户金额:"))
     9 while True:
    10     for i,p in enumerate(shp):
    11         print i,p[0],p[1]
    12     enther = raw_input("请输入要购买的商品序号:").strip()
    13     if enther.isdigit():
    14         enther = int(enther)
    15         #p_price = products[choice][1]
    16         pric = shp[enther][1]
    17         if pric <= e:
    18             pric_list.append(shp[enther])
    19             e -= pric
    20             print "您购买的%s已添加到购物车,剩余金额%s" %(shp[enther][0],e)
    21         else:
    22             print "金额不足,请重新选择,剩余金额%s" % e
    23     elif enther == 'quit':
    24         print "购买的商品列表"
    25         for k,v in enumerate(pric_list):
    26             print k,v
    27             print "剩余金额为%s" % e
    28         print "-----欢迎再次光临------"
    29         break

    实现了输入金额后购买商品直到金额不足

  • 相关阅读:
    HttpServletResponse对象
    FastJSON 简介及其Map/JSON/String 互转(转载)
    commons-lang3-3.4类库
    HttpClient相关
    JSON.parse()方法 (转载)
    textview用法--推荐
    每日总结
    百度网盘
    每日总结
    每日总结
  • 原文地址:https://www.cnblogs.com/guigujun/p/6129200.html
Copyright © 2011-2022 走看看