[英]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.