Python:1个函数可以接受来自2个不同函数的变量吗

Python:1个函数可以接受来自2个不同函数的变量吗,python,Python,好的-我试图让Python函数接受来自另外两个函数的变量。这可能吗 def calculate_deposit(total_cost, extras): deposit_percent = float(raw_input("Enter Deposit % (as a decimal) of Total Cost: ")) months_duration = float(raw_input("Enter the number of months client requires

好的-我试图让Python函数接受来自另外两个函数的变量。这可能吗

def calculate_deposit(total_cost, extras):
    deposit_percent = float(raw_input("Enter Deposit % (as a decimal) of Total Cost:    "))
    months_duration = float(raw_input("Enter the number of months client requires:    "))
    if deposit_percent >0:
        IN HERE JUST SOME CALCULATIONS
    else:
        print "The total amount required is:     ", total_cost

def rectangle(width, height, depth, thickness):
    type = raw_input("Enter lowercase c for concrete:  ")
    if type == 'c':
        output = IN HERE JUST COME CALCULATIONS
    else:
        return raw_input("Oops!, something went wrong")     
    print output + extras()
    total_cost = calculate_deposit(output, extras)                          

def extras():
    type = float(raw_input("Enter 1 for lights:  "))
    if type == 1:
        light = 200
        print "The cost of lights are:    ", light
        return light
    else:
        return raw_input("No extras entered")
下面是我试图做的一个示例(我已经简单地编写了原始代码,以便在这里输入)。希望你能理解我的想法。简而言之,我有一个矩形()调用Extras(),我希望矩形和Extras的输出被发送到Calculate\u Deposit()

这可能吗

def calculate_deposit(total_cost, extras):
    deposit_percent = float(raw_input("Enter Deposit % (as a decimal) of Total Cost:    "))
    months_duration = float(raw_input("Enter the number of months client requires:    "))
    if deposit_percent >0:
        IN HERE JUST SOME CALCULATIONS
    else:
        print "The total amount required is:     ", total_cost

def rectangle(width, height, depth, thickness):
    type = raw_input("Enter lowercase c for concrete:  ")
    if type == 'c':
        output = IN HERE JUST COME CALCULATIONS
    else:
        return raw_input("Oops!, something went wrong")     
    print output + extras()
    total_cost = calculate_deposit(output, extras)                          

def extras():
    type = float(raw_input("Enter 1 for lights:  "))
    if type == 1:
        light = 200
        print "The cost of lights are:    ", light
        return light
    else:
        return raw_input("No extras entered")

矩形中
调用
extras()
,然后只将函数
extras
发送到
计算存款()
。您希望发送
extras()
调用的结果,而不是函数本身的引用。您可以进行微小更改并保存该值,在打印和进入
计算押金
时参考该值

更改此项:

print output + extras()
total_cost = calculate_deposit(output, extras)
为此:

extra = extras()
print output + extra
total_cost = calculate_deposit(output, extra)

矩形中
调用
extras()
,然后只将函数
extras
发送到
计算存款()
。您希望发送
extras()
调用的结果,而不是函数本身的引用。您可以进行微小更改并保存该值,在打印和进入
计算押金
时参考该值

更改此项:

print output + extras()
total_cost = calculate_deposit(output, extras)
为此:

extra = extras()
print output + extra
total_cost = calculate_deposit(output, extra)