zoukankan      html  css  js  c++  java
  • 购物车练习

    #__author__:Administrator}
    #data: 2017/11/2

    product_list = [

    ('Mac',9000),
    ('kindel',800),
    ('tesla',900000),
    ('python_book',105),
    ('bike',2000),

    ]

    saving = input('please input a money:')
    shopping_car = []
    if saving.isdigit():
    saving = int(saving)
    #方法一
    # for i in product_list:
    # print(product_list.index(i),i)

    #方法二
    while True:
    for i ,v in enumerate(product_list,1):
    print(i,v)
    choice = input('请选择商品编号[退出:q]:')

    if choice.isdigit():
    choice = int(choice)
    if choice>0 and choice<=len(product_list):
    p_item = product_list[choice-1]

    if p_item[1]<saving:
    saving -= p_item[1]
    shopping_car.append(p_item)
    else:
    print('余额不足,还剩%s'%saving)
    print(p_item)
    else:
    print('编码不存在')
    elif choice=='q':
    print('-----------您已经购买如下商品--------------')
    for i in shopping_car:
    print(i)
    print('您还剩%s' % saving)
    break

    else:
    print('非法字符')
  • 相关阅读:
    Maven跳过测试
    Maven教程
    使用订单号加锁
    SpringMVC重定向路径中带中文参数
    并发文章
    maven clean插件使用进阶
    线程池基础
    Session中短信验证码设置有效时间
    Linux命令
    下载并安装Cent OS 6.5
  • 原文地址:https://www.cnblogs.com/xuxu-learn-python/p/7773219.html
Copyright © 2011-2022 走看看