• 嵌套列表实现购物车项目


    嵌套列表实现购物车项目

    #_author:Administrator
    #date:2019/10/25
    #购物车程序
    salary=int(input("please input your salary:"))
    print("购物清单如下")
    msg='''
    ---------购物清单---------
    1.iphone11 5800
    2.mac book 9000
    3.coffee 38
    4.python book 80
    5,bicycle 1200
    --------------------------
    '''
    print(msg)
    balance=0
    shopping_car=[]

    while True:
    i = int(input("请输入你要购买的商品编号:"))

    super_shopping=[[],['iphone11',5800],['mac book ',9000],['coffee ',38],['python book',80],['bicycle',1200]]
    balance = salary - super_shopping[i][1] #list[i]
    if balance<0:
    print("你的余额不足为,%d,请重新选择:你还需要购买东西吗?[yes/no]"%balance)

    say=input("请输入:")
    if say=="yes":

    continue
    else:
    print("欢迎再次光临")

    print("你的购物车有如下商品:")
    print(shopping_car)
    break



    else:
    shopping_car.append(super_shopping[i][0])#将该商品加入域购物车

    print("该商品已加入购物车,当前余额为%d"%balance)
    print("您是否要去付款呢?[yes/no]")
    to_pay=input("请输入:")
    if to_pay=='yes':
    salary=balance
    continue
    else:
    #此处可以一一打印购买的商品
    print("你还需要购买其他商品吗?[yes/no]")
    answer=input("your answer:")
    if answer=="yes":
    salary=balance
    if salary<0:
    break

    else:
    continue
    else:
    print("欢迎您的光临")
    print("你的购物车有如下商品:")
    print(shopping_car)
    break
    Output:

    please input your salary:5880
    购物清单如下

    ---------购物清单---------
    1.iphone11 5800
    2.mac book 9000
    3.coffee 38
    4.python book 80
    5,bicycle 1200
    --------------------------

    请输入你要购买的商品编号:1
    该商品已加入购物车,当前余额为80
    您是否要去付款呢?[yes/no]
    请输入:yes
    请输入你要购买的商品编号:4
    该商品已加入购物车,当前余额为0
    您是否要去付款呢?[yes/no]
    请输入:yes
    请输入你要购买的商品编号:1
    你的余额不足为,-5800,请重新选择:你还需要购买东西吗?[yes/no]
    请输入:no
    欢迎再次光临
    你的购物车有如下商品:
    ['iphone11', 'python book']

  • 相关阅读:
    maven工程目录结构&常用命令
    slf4j 与 log4j2 实战讲解与日志分割
    跟着大神学zookeeper分布式锁实现-----来自Ruthless
    redis分布式锁Redisson扩展
    Redis分布式锁---完美实现
    redis异常Redis:java.util.NoSuchElementException: Unable to validate object at
    boot中 Quartz注入spring管理类失败
    转载一篇必须超级好的JVM配置实战
    uoj#422. 【集训队作业2018】小Z的礼物(MIn-Max容斥+插头dp)
    uoj#420. 【集训队作业2018】矩形(组合数学)
  • 原文地址:https://www.cnblogs.com/startl/p/11739156.html
Copyright © 2020-2023  润新知