如何调用另一个函数中的函数进行计算


def warehouseInventoryCreationBios():
bios = []
warehouseName = ["nWarehouse: WBS"]
bios.append(warehouseName)
warehouse_initial_quantity_aircondSec = 1000    
aircondSec = ["Section: AS", "Parts: compressor", "Part ID: ABS01", "Initial Quantity in the warehouse:", warehouse_initial_quantity_aircondSec, 'n']
bios.append(aircondSec)
.
.
return bios
warehouseInventoryCreationBios()
def updateBiosWarehouseInventory():
bios = warehouseInventoryCreationBios()
warehouseUpdateSupplier = []
name = input('Enter Supplier name: ')
name = name.lower()
id_parts = input('The id of the part: ')
id_parts = id_parts.upper()
order_from_supplier = int(input('How many orders from supplier: '))
warehouseUpdateSupplier.append(name)
warehouseUpdateSupplier.append(id_parts)
warehouseUpdateSupplier.append(str(order_from_supplier))
if name == 'tab':
if id_parts == "ABS01" or id_parts == "TBS05" or id_parts == "BBS02":
if id_parts == "ABS01":
compressor_quantity_warehouse = warehouse_initial_quantity_aircondSec + order_from_supplier
return compressor_quantity_warehouse
.
.
return warehouseUpdateSupplier
updateBiosWarehouseInventory()

输入:Enter Supplier name: tab

The id of the part: abs01

How many orders from supplier: 100

输出:NameError: name 'warehouse_initial_quantity_aircondSec' is not defined

如何将第一个函数中的值warehouse_initial_quantity_aircondSec与第二个函数中的warehouse_initial_quantity_aircondSec相加

新手来了,对不起>lt;

您正试图在第二个函数中使用一个变量,该变量在第一个函数中被定义为局部变量,您应该返回该值以使用它:

def warehouseInventoryCreationBios():
bios = []
warehouseName = ["nWarehouse: WBS"]
bios.append(warehouseName)
warehouse_initial_quantity_aircondSec = 1000    
aircondSec = ["Section: AS", "Parts: compressor", "Part ID: ABS01", "Initial Quantity in the warehouse:", warehouse_initial_quantity_aircondSec, 'n']
bios.append(aircondSec)
.
.
# return multiple values (as tuple)
return bios, warehouse_initial_quantity_aircondSec 
warehouseInventoryCreationBios()  # this line is unnecessary, only calculations with no results used after it
def updateBiosWarehouseInventory():
# receive multiple values
bios, warehouse_initial_quantity_aircondSec = warehouseInventoryCreationBios()
warehouseUpdateSupplier = []
name = input('Enter Supplier name: ')
name = name.lower()
id_parts = input('The id of the part: ')
id_parts = id_parts.upper()
order_from_supplier = int(input('How many orders from supplier: '))
warehouseUpdateSupplier.append(name)
warehouseUpdateSupplier.append(id_parts)
warehouseUpdateSupplier.append(str(order_from_supplier))
if name == 'tab':
if id_parts == "ABS01" or id_parts == "TBS05" or id_parts == "BBS02":
if id_parts == "ABS01":
compressor_quantity_warehouse = warehouse_initial_quantity_aircondSec + order_from_supplier
return compressor_quantity_warehouse
.
.
return warehouseUpdateSupplier
updateBiosWarehouseInventory()  

最新更新