Итак, я пишу простую программу для расчета объема для куба на основе пользовательского ввода.У меня есть main.py и volume.py.В main.py я просто вызываю соответствующую функцию cubeVolume.Однако, когда я пытаюсь добавить полученный том куба из volume.py в список в main.py с именем cubeList, я получаю неопределенную ошибку.Как я могу это исправить?
#main.py
from volume import cubeVolume
import math
cubeList = []
userInput = str(input("Enter the shape you wish to calculate the volume for: "))
userInput = ''.join(userInput.split()).lower().capitalize()
while userInput != "Q" or userInput != "Quit":
if userInput == "C" or userInput == "Cube":
cubeSide = int(input("Enter the side length for the Cube: "))
cubeVolume(cubeSide)
cubeList.append(volume)
Вот файл volume.py
#volume.py
import math
def cubeVolume(side):
volume = side**3
print("The volume of the cube with side length {} is: {}".format(side, volume))
Вот мой вывод:
Enter the shape you wish to calculate the volume for: cube
Enter the side length for the Cube: 3
The volume of the cube with side length 3 is: 27
Traceback (most recent call last):
File "/Users/User/Desktop/folder2/main.py", line 14, in <module>
cubeList.append(volume)
NameError: name 'volume' is not defined