zoukankan      html  css  js  c++  java
  • 简单购物车程序(Python)

    #简单购物车程序:
    money_all=0
    tag=True
    shop_car=[]
    shop_info={
    'apple':10,
    'tesla':100000,
    'mac':3000,
    'lenovo':30000,
    'chicken':10,
    }
    while tag:
    for k,v in shop_info.items():
    print('商品名:{name}价格:{price}'.format(name=k,price=v))
    goods=input('请输入你要买的商品:').strip()
    if len(goods)==0 or goods not in shop_info:
    continue
    while tag:
    if goods in shop_info:
    count=input('请输入你要购买的数量:').strip()
    if len(count)==0 or count.isdigit()==False:
    print('输入有误,请重新输入')
    continue
    shop_car.append((goods,shop_info[goods],int(count)))#将商品名,价格,数量以元祖的形式保存到列表中

    print('''
    你的购物车如下:
    %s

    '''%(shop_car))
    cmd =input('退出请输入N,其他键继续购买').strip()
    if cmd == 'N' :
    for item in shop_car:
    _,x,y=item#取列表元祖中的后两个值
    money_all+=int(x)*int(y)
    print(
    '''
    **********你总共消费了************

    ********** %s 元 *************

    **********欢迎下次光临**************

    '''%(money_all)
    )
    tag=False
    else:
    break



    运行效果如下:









  • 相关阅读:
    高精度乘除运算优化
    高精度除法
    高精度乘法
    期末考试
    P2341 [HAOI2006]受欢迎的牛[SCC缩点]
    P2002 消息扩散[SCC缩点]
    神奇搜索算法A*
    P3205 [HNOI2010]合唱队[区间dp]
    P4170 [CQOI2007]涂色
    P1220 关路灯[区间dp]
  • 原文地址:https://www.cnblogs.com/wxp5257/p/7216546.html
Copyright © 2011-2022 走看看