简体   繁体   中英

error while importing a library in a program

I tried to write a program but when I try to import my library it shows the following error.

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

I saved the above program as addon1

When I try to call that program

import addon1.py as re
print('Choices')
print(['1-to find it is a prime no'],['2-Find factorial'],['3'])... 
# not completed yet

It's showing an error at the first line itself.

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.

Leave off the file extension, it should work.

import addon1 as re

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM