模拟购物系统——python基础(原题来自B站)https://www.bilibili.com/video/BV12E411A7ZQ?p=9

模拟购物系统——python基础(原题来自B站)https://www.bilibili.com/video/BV12E411A7ZQ?p=9_第1张图片

#购物
products = [['小米',1600],['苹果',3000],['华为',1500],['oppo',1000],['vivo',1000]]
print("--------商品列表--------")
j = 0
index = 0
shops = []
money = []
x = [0,1,2,3,4]
for i in products:
    print(' %d    %s   %d'%(j,i[0],i[1]))
    j += 1
while True:
    z = input('您需要什么:')
    if z.isdigit():
        z = int(z)
        if (z in x):
            shops.append(products[z])
            money.append(products[z][1])

        else :
            print('输入有误!')
            break

    elif(z == 'p'):
        g = 0
        sum = 0
        print("-------购物车-----------")
        for shop in shops:
            g += 1
            for i in shop:
                print(i,end='\t')
            print('\n')
        for mon in money:
            sum += mon


        

你可能感兴趣的:(python)