python代码训练1(购物车)

python代码训练1(购物车),第1张

python代码训练1(购物车)

products = [['iphone', 6888], ['MacPro', 14800], ['小米6', 2499], ['Coffee', 31], ['Book', 60], ['Nike', 600]]
print('-'*6+'商品列表'+'-'*6)
i = 0
for product in products:
    print(i, end='t')
    for detail in product:
        print(detail, end='t')
    print('n')
    i += 1
shopping_list = []
while True:
    respond = input('请选择您要购买的商品号码:(如需退出请输入‘q’)')
    if respond == 'q':
        break
    shopping_list.append(products[int(respond)])

print('-'*30)
print('您的商品清单是:')
n = 1
for goods in shopping_list:
    print(n, end='t')
    for detail in goods:
        print(detail, end='t')
    n += 1
    print('n')
cost = 0
for value in shopping_list:
    cost += int(value[1])
print('总计:%d'%cost)

运行结果:

没有添加中断代码,可自行补充。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5700979.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存