zoukankan      html  css  js  c++  java
  • 购物车 python作业


    功能要求:

    要求用户输入总资产,例如: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},
    ]
    zzc = int(input('请输入总资产:'))
    car = []
    while True:
    for i1 in enumerate(goods):
    print(i1[0],i1[1].get('name'),i1[1].get('price'))
    ret = int(input('请根据序号选择商品,退出输入88:'))
    for i2 in enumerate(goods):
    if i2[0] == ret:
    car.append(goods[ret])
    print(car)
    if ret == 88:
    for i3 in car:
    zj = 0
    zj = i3['price'] + zj
    if zj > zzc:
    print('余额不足,请充值')
    # xz = input('余额不足,选择充值输入y,退出购买输入n:')
    # if xz == 'y':
    # jj = int(input('请输入充值金额:'))
    # zzc = jj + zzc
    # else:
    # print('欢迎下次光临')
    else:
    print('购买成功')
    break


  • 相关阅读:
    模型层
    视图层,模板层
    ORM表关系建立
    CMakeList入门
    C++标准模板库
    C++基本语法
    g++应用说明
    Linux快捷键
    Git 操作备忘
    Block的详细介绍
  • 原文地址:https://www.cnblogs.com/koushuige/p/7800224.html
Copyright © 2011-2022 走看看