Return variable from python module

I don't know how to get the variables a and b in my main program where i imported a module.

scipt1.py:

def med():

    import math
    n=int(input("n: \n"))
    x=float(input("media: \n"))
    s2=float(input("s2: \n"))
    t=float(input("t_{a/2, n-1}: \n"))

    a=x-(t*math.sqrt(s2/n))

    b=x+(t*math.sqrt(s2/n))
    return a,b

in scipt2.py:

from script1 import med

med()

#for example I want to do
x = a - 1000
y = b + 1000

but I get: "NameError: name 'a' is not defined" although I can input the values of the variables n,x,t,s2. What I am doing wrong?

Upvotes: 1

Views: 560

Answers (1)

Kuldeep Singh Sidhu
Kuldeep Singh Sidhu

Reputation: 3856

from script1 import med

a,b = med() #store the values that your function returns

#for example I want to do
x = a - 1000
y = b + 1000

Upvotes: 3

Related Questions