Return 来自 python 模块的变量

Return variable from python module

我不知道如何在导入模块的主程序中获取变量 a 和 b。

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

在scipt2.py中:

from script1 import med

med()

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

但我得到:"NameError: name 'a' is not defined" 虽然我可以输入变量 n、x、t、s2 的值。 我做错了什么?

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