如何在另一个函数中使用函数的两个返回值?主要()

时间:2015-04-16 01:14:03

标签: python

我的计划:

findGrid(n):   #This function takes one parameter.
    row = n + 1
    col = row ** 2

    return  row, col                  #Return two values

calculate(a, b):
    p = a + b

    return p

main():
    x = eval(input("Enter a number: "))
    y = findGrid(x)

我的问题是如何在函数findGrid()中使用函数calculate()中的两个返回值?请帮忙!

1 个答案:

答案 0 :(得分:0)

另一个答案不起作用。您需要正确声明您的功能。

def findGrid(n):   #This function takes one parameter.
    row = n + 1
    col = row ** 2

    return  row, col                  #Return two values

def calculate(a, b):
    a = a + 2
    b = a // 2

    return a, b

def main():
    x = int(input("Enter a number: "))
    y,z = findGrid(x)
    a,b = calculate(y, z)
    print a
    print b

main()
相关问题