我试图将一个模块导入到我的main.py python文件中,这两个文件都在同一个目录中

2024-09-30 01:31:04 发布

您现在位置:Python中文网/ 问答频道 /正文

def volumeofcube():
    a = int(input('Enter the length of the side:'))
    volume = a**3
    #Rounded to one decimal place
    volume = str(round(volume, 1))
    #The volume is added to its corresponding list
    volumeofcubelist.append(volume)
    print('The volume of the cube with the side', a,'is', volume)
    return volume

这是一个我想导入到另一个文件(main.py)中的函数,它的工作方式如下:

elif shape == 'cube':
    volumeofcube()

但是,当我尝试导入时:

import volumes
or
from volumes import volumeofcube()

这些都无法找到volumes.py模块并将其导入


Tags: ofthetopyimportinputisdef

热门问题