繁体   English   中英

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

[英]How to use two returned values from a function in another function? MAIN()

我的程序:

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() 请帮忙!

另一个答案不起作用。 您需要正确声明函数。

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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM