python案例6-自动售卖机系统

str = [
    ["1", "农夫山泉", 2, 12],
    ["2", "百事可乐", 3, 12],
    ["3", "可口可乐", 3, 12],
    ["4", "阿萨姆", 4, 6],
    ["5", "脉动", 4, 12]
]
q = 4
money = int(input("请输入您的金额:"))
while True:
    if q == 0:
        break
    while q == 2 or money == 0:
        print("欢迎进入管理员系统!!!")
        for i in str:
            print("商品编号:%s,商品名称:%s,商品个数:%d" % (i[0], i[1], i[3]))
        sum = input("请输入商品编码:")
        if sum == "0":
            q = 0
            break
        while sum not in (i[0] for i in str):
            sum = input("请输入商品编号:")

        sum1 = int(input("添加:"))
        while sum1 < 0:
            sum1 = int(input("添加:"))

        for i in str:
            if sum == i[0]:
                i[3] += sum1
                break

    while q == 0:
        i = input("0.退出 1.测试")
        if i == "0":
            break
        else:
            q = 1
            money = 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999
            break

    while True:
        if q == 0:
            print("欢迎下次再来!!!")
            break
        else:
            print("————————————商品信息——————————————")
            for i in str:
                print("商品编号:%s,商品名称:%s,商品单价:%d,商品个数:%d" % (i[0], i[1], i[2], i[3]))

            print("                                                 账户余额:%d元" % money)
            buy = input("请输入想要购买的商品编号:")
            if buy == "00":
                q = 2
                break
            if buy == "0":
                print("欢迎下次再来!!!")
                break
            while buy not in (i[0] for i in str):
                buy = input("请输入想要购买的商品编号:")

            sum4 = int(input("您想购买几瓶:"))

            for i in str:
                if i[0] == buy:
                    if i[3] >= sum4:
                        if money - sum4 * i[2] >= 0:
                            money -= sum4 * i[2]
                            i[3] -= sum4
                            print("购买成功!!!")
                            print(40 * "*")
                            break
                        else:
                            print("抱歉,您的金额不足!!!")
                            break
                    else:
                        print("抱歉,您要购买的商品没有库存了!!!")
                        break


你可能感兴趣的:(python案例,开发语言,python,python)