python之简陋的数据库

lists = []
shop1 = [['鸭梨',18],['桃子',30],['苹果',21],['榴莲',5],['香蕉',3]]
#商品列表
shop2 = [['胡萝卜',11],['香菜',21],['圆白菜',3],['土豆',2],['地瓜',4]]
shop_type = [['水果',shop1],['蔬菜',shop2]]
#商品类型列表
while True:  #死循环
    n = 1  #前标
    print('商品分类')
    print('**********************')
    for a,b in shop_type:
        print(str(n)+a)
        n = n + 1
    print('**********************')
    num1 = int(input("输入商品类型(输入0进行结算):"))
    if num1 ==0:
        break
    while True:
        m = 1
        print('**********************')
        if num1 == 1:
            for a,b in shop1:
                print(str(m) + a,b)
                m=m+1
                a = shop1
        elif num1 == 2:
            for a,b in shop2:
                print(str(m) + a, b)
                m = m + 1
                a = shop2
        print('**********************')
        num2 = int(input("输入购买商品(输入0返回首页):"))-1
        if num2 == -1:
            break
        num3 = int(input("输入购买商品数量:"))
        n_lists=[]
        n_lists.append(a[num2][0])
        #将商品名称放入空列表
        n_lists.append(num3)
        # 将商品数量放入空列表
        n_lists.append(a[num2][1])
        # 将商品单价放入空列表
        n_lists.append(a[num2][1]*num3)
        # 将商品合计放入空列表
        lists.append(n_lists)
        print('商品名称  商品数量  商品单价  合计金额')
        for a, b, c, d in lists:
            print('  ' + str(a) + '  ', '  ' + str(b) + '  ', '   ' + str(c) + '   ', '   ' + str(d) + '  ')

x = 0
print('商品名称  商品数量  商品单价  合计金额')
for a,b,c,d in lists:
    print('  '+str(a) +'  ','  '+str(b)+'  ','   '+str(c)+'   ','   '+str(d)+'  ')
    x += d
print('需支付金额:' + str(x))

 

posted @ 2020-11-20 20:31  秋叶落日  阅读(106)  评论(0)    收藏  举报