-1

I want to return a value in a script MAIN.py where the function is stated in another script? How do I do this?

In a function SUB.py I have defined:

def SUM_POWER(a,b):
    c = a+b
    d = a**b
    return [c,d]

Now I want to get in a script MAIN.py: c and d for a=3 and b=4. I tried in MAIN.py:

import SUB
c,d = SUM_POWER(3,4)

What do I do wrong? Preferably I would want to name the variables in MAIN.py different than c,d. So for example out1, out2. out1 has to correspond to c and out2 corresponds to d by the order in which the values are returned.

Jeroen
  • 801
  • 6
  • 20

1 Answers1

1

The problem is in function call, as well as that you are returning a list while trying to store it in a tuple.

Try this SUB.py -

def SUM_POWER(a,b):
c = a+b
d = a**b
return c,d

MAIN.py -

import SUB
c,d = SUB.SUM_POWER(3,4)
Aditya Singh
  • 332
  • 2
  • 12