python - 如何在另一个函数中调用一个函数进行计算?
问题描述
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
新手,见谅><
解决方案
您试图在第二个函数中使用一个变量,该变量在第一个函数中定义为局部变量,您应该返回该值以使用它:
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()
推荐阅读
- reactjs - 为什么我不能将一般 JSX 传递给反应中的包装组件?
- git - 如何从 vsts 构建任务连接到 TfsGit
- ios - 如何在单个 UIView 中添加 3 种背景颜色?
- ruby - Rubocop 缩进配置
- python - 小数字段的选择
- angular - Angular6 - HttpClient在使用socket.io-client时缓存请求
- javascript - 我可以将 Angular toPromise 方法的 http 客户端转换为异步并等待吗?
- performance - 从内部表中填充范围表而不重复
- javascript - amazon-cognito-identity-js 刷新令牌过期处理
- ckeditor - 在laravel中将图像上传到ckeditor服务器响应不正确