我尝试编写程序但是当我尝试导入我的库时,它显示以下错误。
def isprime(a):
for i in range(2,a):
if(a%i==0):
return False
break
else:
return True
def fact(a):
f=1
i=a+1
for i in range(1,i):
f=f*i
return f
def sum(a):
f=0
i=a+1
for i in range(1,i):
f=f+i
return f
def sub(a,b):
z=a+b
return f
def add(a,b):
z=a-b
return f
我将上述程序保存为addon1
当我尝试调用该程序时
import addon1.py as re
print('Choices')
print(['1-to find it is a prime no'],['2-Find factorial'],['3'])...
# not completed yet
它在第一行显示错误。
Traceback (most recent call last):
File "C:\Users\Revanth's\AppData\Local\Programs\Python\Python36-32\main.py", line 1, in <module>
import addon1.py
ModuleNotFoundError: No module named 'addon1.py'; 'addon1' is not a package.
答案 0 :(得分:1)
不要使用文件扩展名,它应该可以正常工作。
将addon1导入为