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

    “继续奔跑 输掉一切也不要输掉微笑”
  • 相关阅读:
    五种实用DOM方法总结
    九月工作总结
    八月下半月工作总结
    【工作总结】七月底-八月中
    权限管理功能的实现
    JavaWeb项目出现红色感叹号
    项目中遇到的AngularJs问题
    五月工作总结
    生成流水号的优化
    AngularJS scope 作用域的问题
  • 原文地址:https://www.cnblogs.com/zycorn/p/9275555.html
Copyright © 2011-2022 走看看