zoukankan      html  css  js  c++  java
  • ----------简单购物车小程序----------

    功能要求:
    要求用户输入自己拥有总资产,例如:2000
    显示商品列表,让用户根据序号选择商品,加入购物车
    购买,如果商品总额大于总资产,提示账户余额不足,否则,购买成功。
    goods = [
    {"name": "电脑", "price": 1999},
    {"name": "鼠标", "price": 10},
    {"name": "游艇", "price": 20},
    {"name": "美女", "price": 998},
    ]
    goods = [
        {"name": "电脑", "price": 1999},
        {"name": "鼠标", "price": 10},
        {"name": "游艇", "price": 20},
        {"name": "美女", "price": 998},
    ]
    
    a = 0
    count = 1
    dic = {}
    li = []
    c = 0
    sum = 0
    s = int(input("请输入你的资产:"))
    while count < 5:
        print("%s  %s  %s" % (count,goods[a]["name"],goods[a]["price"]))
        dic[count] = goods[a]
        count += 1
        a += 1
    while 1:
        s1 = input("请你选择要加入购物车的商品(按Q结束选购进行付款):")
        if s1.upper() == "Q":
                break
        elif int(s1) > int(4):
            print("输入有误,请重新输入")
        else:
            li.append(dic[int(s1)]["price"])
            print("%s" % (dic[int(s1)]["price"]))
        c += 1
    if int(li[0]) + int(li[c - 1]) > int(s):
        print("帐户余额不足")
    else:
        print("购买成功!")

    2018-07-06  21:06:16

    “继续奔跑 输掉一切也不要输掉微笑”
  • 相关阅读:
    霍尔逻辑(Floyd-Hoare Logic)
    解决状态空间爆炸的方法简介
    模型检测工具汇总
    模态逻辑
    linux修改apt-get 源
    Vmware宿主机无法复制粘贴内容到虚拟机中
    用tkinter.pack设计复杂界面布局
    什么是跨域,以及解决方案
    python爬虫
    JS中的原型和原型链(图解)
  • 原文地址:https://www.cnblogs.com/zycorn/p/9275555.html
Copyright © 2011-2022 走看看