简体   繁体   English

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

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

MY PROGRAM: 我的程序:

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)

My question here is that how to use two return values from the function findGrid() in the function calculate() ? 在这里,我的问题是,如何利用两个返回值从函数findGrid()的函数calculate() Please help! 请帮忙!

The other answer does not work. 另一个答案不起作用。 You need to declare your functions properly. 您需要正确声明函数。

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.

相关问题 如何使用itertools将返回的值从一个函数传递给另一个函数? - How to use itertools to pass the returned values from one function to another? Python:使用从一个函数返回的值到另一个函数 - Python: Use returned values from a function to another function 如何在另一个函数中使用 main 中的变量? - How to use a variable from main in another function? 如何从另一个 function 访问返回的 function 值 - How to access returned function values from another function 通过另一个函数访问一个函数的返回值 - Accessing returned values from a function, by another function 如何在另一个 function 中使用前一个 function 返回的变量? (Python) - How to use a returned variable from a previous function in another function? (python) 如何从一个函数返回两个值,然后将它们都用作另一个函数的参数中的两个参数 - How to return two values from a function and then use both of them as parameters within the parameter of another function as two parameters 如何在另一个 function 中使用返回的列表? - How to use a returned list from one function in another? 使用函数的返回值作为另一个 function 的参数 - Use a function's returned values as parameters for another function 无法将返回的值从函数传递给python中的另一个函数 - Cannot pass returned values from function to another function in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM