Python:函数无法保留值的问题

时间:2018-11-03 06:06:22

标签: python-3.x function scope global-variables user-input

我的问题是我正在编写一个处理不同数据的多个输入/输出的程序。结果,我需要在用户输入数据时必须保留其值的功能。但是,这在我运行代码时似乎没有发生。我得到的错误是“ ...缺少2个位置参数”。该代码确实可以运行并从用户那里获得输入,但是当它在程序底部被调用时,它似乎根本没有“挂在”输入上。那么如何调整此代码以允许用户输入使用自变量?

这是代码:

导入数学

def query():

road_length = int((float(input('Insert the amount of road length that is needed in miles: '))))
num_lanes = int(input('Insert the amount of lanes that are wished for this highway: '))

depth_asphalt_inches = int(input('Insert the total asphalt depth that you wish to use in inches: '))

pipe_power_length = int(input('Insert the amount of pipe that will be placed underground: '))

def calc_num_stoplights(road_length,num_lanes):

query() 

stoplights = (2 + num_lanes) * road_length
print(stoplights)

return stoplights

def calc_asphalt_truckloads(road_length,num_lanes,asphalt_depth_inches):

query()

road_to_ft = road_length * 5280    
lanes_to_ft = num_lanes * 12    
depth_asphalt = asphalt_depth_inches / 12
volume_asphalt_ft = depth_asphalt * road_to_ft * lanes_to_ft   
weight_asphalt = volume_asphalt_ft * 145    
asphalt_quantity_use = round(weight_asphalt / 10000) 
calc_asphalt_truckloads = asphalt_quantity_use

print(calc_asphalt_truckloads)
return calc_asphalt_truckloads

def calc_pipe_power_need(road_length,pipe_power_length):

power_cable = road_length * 5280 / 20
water_pipe = road_length * 5280 / 10
round(power_cable)
round(water_pipe)

print(calc_pipe_power_need)
return(calc_pipe_power_need)

query()

calc_pipe_power_need()

0 个答案:

没有答案