You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python库存管理问题:出库时扣减库存功能实现求助

求助:库存管理系统出库函数无法实现库存扣减功能

我是Python新手,正在开发库存管理系统,其中Release_Materials函数的目标是实现出库操作时扣减对应商品的库存,但目前这个函数运行有问题,达不到预期效果。

以下是该函数的代码:

def Release_Materials():
    print("==================")
    print("Release Materials")
    print("==================")
    for item in inventory:
        item_index = int(input("what is the index of the item you would like to change? (type 0 to cancel): ")) - 1
        if item_index == "0":
            return
        if item_index < 0:
            return
        if check_valid_index(item_index) == False:
            print("")
            print("Error: The Index Does not exist! ")
            return
        else:
            break
        quantity = int(input("what is the quantity of item you would like to change? (type 0 to cancel): "))
        if quantity == "0":
            return
        if quantity < 0:
            return
        print(f"{inventory[item_index].get_name()} - OLD QUANTITY: {inventory[item_index].get_stock()}")
        inventory[item_index].update_stock(quantity)
        print(f"{inventory[item_index].get_name()} - NEW QUANTITY: {inventory[item_index].get_stock()}")
        print("Quantity Successfully Updated! ")
    else:
        print("No items added yet! ")

MenuDisplay()

内容的提问来源于stack exchange,提问作者Joven Rey Flores

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 00:15:34