0

I have a fully functional code with three functions each of which returns outputs of it own. My task is to create one function which can call all the other functions and return the outputs of all the functions. how do I do that? My code is as follows:

def func(x, y):
    return x * x + y * y, x * y

def generate_data(size):
    nx = 5
    mx = 0.5
    mux, sigmax = nx, mx/3
    ny = 3
    my = 0.9
    muy, sigmay = ny, my/3
    result1=[]
    result2=[]
    for i in range(size):
        result = func(random.gauss(mux, sigmax), random.gauss(muy, sigmay))
        result1.append(result[0])
        result2.append(result[1])
    return result1, result2

def analysis(ls):

    avg = np.mean(ls)
    std = np.std(ls)
    pre = 3 * std


    return avg, std, pre

say, for eg: I need to create a function

def My_func()

and this function should have the other functions and returns its outputs

2 Answers 2

3

Just as you have done in each of your existing functions, you can return multiple results in one line.

def My_func(x, y, size, ls):
    return analysis(ls), generate_data(size), func(x,y)
Sign up to request clarification or add additional context in comments.

1 Comment

No, but the My_func should take all the inputs.. the other functions should not have parameters..
0

You can return them at once.Like this:

return analysis(x,y), generate_data(size), func(ls)

To receive the value, you have to unpack

Valanalysis,Valgenerate_data,valfunc=My_func(x, y,size,ls)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.