Python爬虫编程基础5天速成【习题3】用Python完成购物车简单操作

#题目:

答案:

products = [["iphone", 6888], ["MacPro", 14800], ["小米6", 2499], ["Coffee", 31], ["Book", 60], ["Nike", 699]]

print("-" * 5, "\t", "商品列表", "-" * 5)
a = 0
for item in products:
    print(a,end="\t")
    print(products[a][0],end="\t")
    print(products[a][1],end="\n")
    a += 1

purchaselist = []
while 1:
    s = input("请问还想购买什么?")
    if s != "q" and -1 < int(s) < 6:
        purchaselist.append(products[int(s)])

    elif s == "q":
        print("-" * 5, "\t", "想要商品列表", "-" * 5)
        c = 0
        for things in purchaselist:
            print(c, end="\t")
            print(purchaselist[c][0], end="\t")
            print(purchaselist[c][1], end="\n")
            c += 1
        break
    else:
        print("你输入的商品不存在")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值