python实现简单的购物车系统

 
''
购物车系统
'''
import sys

product = [[1, '百达翡丽', 4500000], [2, '迈巴赫', 4550000], [4, '古驰', 165000], [6, '兰蔻', 105000], [5, '蒂芙尼', 1075000],
           [3, '思哲', 195000]]

salary = int(input("\n请输入信用卡总额度: "))
cart = []
#
while True:
    for p in product:  # 显示采购物品目录
        print(p)

    choice = int(input("\n请输入采购编号 :"))  # 输入采购编码
    if choice > 0 and choice <= len(product):  # 判断编号符合要求
        index = 0
        for p in product:
            index = index + 1   #定位索引
            if p[0] == choice:  #索引与编码做关联
                print("本次采购商品为:%s " % p)
                salary -= product[index - 1][2] 
                if salary <= 0:
                    print('\n账户余额不足')
                    salary += product[index - 1][2]
                    pass
                else:
                    cart.append(p)

    else:
        print('\nplease input correct num ,num > 0 and num < %d' % len(product))  # 要求编号符合
    print('已经购买商品为: %s , 账户剩余额度: %d' % (cart, salary))
    out = str(input("\n如果离开请输入 'b' :"))
    if out == 'b':
        sys.exit(0)
    else:
        continue
 

 

猜你喜欢

转载自www.cnblogs.com/hqt0731/p/12741887.html