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



    运行效果如下:









  • 相关阅读:
    流体力学笔记 第二章 流体力学的基本概念
    jvm常用的参数
    链表的反转
    数据流中的中位数
    二叉树对称
    二叉树镜像
    输入框校验
    判断单选或者复选框中选中的值
    网页中window.open 弹出 父页面和子页面数值交互
    数组去重
  • 原文地址:https://www.cnblogs.com/wxp5257/p/7216546.html
Copyright © 2011-2022 走看看