简体   繁体   中英

pass two different output in a function

I am not sure if it possible to pass the output of two different functions in another function. Ie output of def A() and def B() are to be passed in to def C().

to make it easy to understand, I chose the following problem as an example.

Problem: I want to Add the product and division of two numbers. For that I made three function

def product(a,b):
  M=a*b

def division(a,b):
  D=a/b

Now I want to add M and D and the result will be (a*b)+(a/b) .

for this I made another function named add to get the sum

def add(M,D):
  X=M+D
  print(X)

But didn't find any way to pass M and D in the add .

You need to return a result from your functions, and then call them in the definition of add

def product(a,b):
  M=a*b
  return M

def division(a,b):
  D=a/b
  return D

def add(a,b):
  return product(a,b) + division(a,b)

Why can't you simply call the functions in add?

def add(a, b):
    return product(a,b) + division(a,b)

 def product(a,b): return a*b def division(a,b): return a/b def add(m, n): return m+n add(product(10,2), division(10,2))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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