python编写购物车的程序

python编写购物车的程序_第1张图片


python编写购物车的程序_第2张图片


python编写购物车的程序_第3张图片


python编写购物车的程序_第4张图片


python编写购物车的程序_第5张图片

python编写购物车的程序_第6张图片


python编写购物车的程序_第7张图片



python编写购物车的程序_第8张图片



product_list=[
    ('Mac',9000),
    ('kindle',800),
    ('tesla',900000),
    ('python book',105),
    ('bike',2000),

]
saving=input('please input your money:')
shopping_car=[]
if saving.isdigit():
    saving=int(saving)
    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):
                #将用户选择商品通过choice取出来
                p_item=product_list[choice-1]

                #如果钱够,用本金saving减去该商品价格,并将该商品加入购物车
                if p_item[1]
python编写购物车的程序_第9张图片 python编写购物车的程序_第10张图片

你可能感兴趣的:(python基础)