Python-POS机生成账单和库存管理

发布于 2025-01-16 23:57:42 字数 2359 浏览 0 评论 0原文

我是Python新手,我正在做一台POS机,可以为我的学校作业生成账单和库存管理。我不知道为什么我输入的产品 id 只会生成两次,但不会连续生成,直到付款的输入为 0 为止。另外,为什么打印出来的账单上没有产品名称,价格只是零呢?

这是我的项目列表

all_products = [
    [1, "Razer Deathadder V2 Pro" , 100, 349.00], 
    [2, "Razer Viper Ultimate",  105, 419.00], 
    [3, "Razer Basilink Ultimate" , 35, 599.00], 
    [4, "Razer Viper mini", 295, 139.00], 
    [5, "Razer Deathadder X", 592, 76.90]
]

生成账单的功能

def generate_bill(product, price, lst):
    print("-" * 40)
    print("\t\tRazer Mouse Shop")
    print("-" * 40)
    print("Bill:{} \tDate:{}".format(int(random.random()*100000), str(datetime.now())))
    print("Product name\t\tprice")
    print("-" * 40)
    for j in range(len(lst)):
        print("{}\t\tRM{}".format(j , item[-1]))
    print("-" * 40)
    print("\t\tTotal Bill Amount: {}".format(price))

当我选择生成账单时的代码

elif choice == 2:
        display_all()
        print("Press 0 for payment")
        item_lst = []
        total_price = 0
        prod_id = int(input("Enter the Product ID: "))
        while prod_id != 0:
            prod_id = int(input("Enter the Product ID: "))
            for item in all_products:
                if item[0] == prod_id:
                    item_lst.append(item[0])
                    total_price = total_price + item[2]
                    if item[1] == 0:
                        print("Sorry we are out of stock")
                    else:
                        item[1] -= 1
                    
                member = input("Do you have membership(Y/N): ")
                if member == "Y":
                    total_price * 0.9
                    generate_bill(item, total_price, item_lst)
                    print("Thanks For shopping with Us")
                    sys.exit(0)
                else:
                    print("Continue Shopping")

输出

点击此 这里的整个代码

我试图在 while 循环中将totalprice += item[2] 更改为totalprice =totalprice + item[2],删除 prodid = int( while 循环中的 input("输入产品 ID: "))。但输出是一样的,totalprice = 0,并且 prod_id 的输入只出现一次,而不是连续出现,直到我输入 0。

I am new to python, I am doing a pos machine that can genarate the bill and inventory management for my school assignment . I had no idea why my input for the product id will only generate twice but not continuosly until the input is 0 for the payment. Other than that, why when the bill is print out there is no product name and the price will be zero only?

this my item list

all_products = [
    [1, "Razer Deathadder V2 Pro" , 100, 349.00], 
    [2, "Razer Viper Ultimate",  105, 419.00], 
    [3, "Razer Basilink Ultimate" , 35, 599.00], 
    [4, "Razer Viper mini", 295, 139.00], 
    [5, "Razer Deathadder X", 592, 76.90]
]

function to generate bill

def generate_bill(product, price, lst):
    print("-" * 40)
    print("\t\tRazer Mouse Shop")
    print("-" * 40)
    print("Bill:{} \tDate:{}".format(int(random.random()*100000), str(datetime.now())))
    print("Product name\t\tprice")
    print("-" * 40)
    for j in range(len(lst)):
        print("{}\t\tRM{}".format(j , item[-1]))
    print("-" * 40)
    print("\t\tTotal Bill Amount: {}".format(price))

The code when i choose to generate bill

elif choice == 2:
        display_all()
        print("Press 0 for payment")
        item_lst = []
        total_price = 0
        prod_id = int(input("Enter the Product ID: "))
        while prod_id != 0:
            prod_id = int(input("Enter the Product ID: "))
            for item in all_products:
                if item[0] == prod_id:
                    item_lst.append(item[0])
                    total_price = total_price + item[2]
                    if item[1] == 0:
                        print("Sorry we are out of stock")
                    else:
                        item[1] -= 1
                    
                member = input("Do you have membership(Y/N): ")
                if member == "Y":
                    total_price * 0.9
                    generate_bill(item, total_price, item_lst)
                    print("Thanks For shopping with Us")
                    sys.exit(0)
                else:
                    print("Continue Shopping")

The output

click this the whole code at here

I had tried to change the totalprice += item[2] to totalprice = totalprice + item[2] in the while loop there, remove the prodid = int(input("Enter the Product ID: ")) from the while loops. But the output just the same, totalprice = 0 and the input for the prod_id just come out one time, not continuosly until i input 0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文