如何导入我在python中创建的函数?

时间:2016-11-27 10:56:05

标签: python python-3.x python-import

很抱歉问这么基本的事情......

我已经制作了这个factorial.py文件:

# Find the factorial of a number
def fact(n):
    p = 1
    for i in range(1, n+1):
        p = p*i
    return p
if __name__ == '__main__':
    n = int(input('Enter an integer to find the factorial of: '))
    f = fact(n)
    print('Factorial of {0}: {1}'.format(n, f))

并保存在C:\Users\usersname

然后在新idle我写了from factorial import fact, 但它导致了如下图所示的错误:

enter image description here

0 个答案:

没有答案