Python 使用参数将函数调用到main
学习python课程 不确定为什么在我的示例中(radius)参数是“未解析引用” 这是我第一次尝试运行此代码,可能会出现更多错误,但让我们关注第一个:P 实用程序.pyPython 使用参数将函数调用到main,python,function,parameters,call,Python,Function,Parameters,Call,学习python课程 不确定为什么在我的示例中(radius)参数是“未解析引用” 这是我第一次尝试运行此代码,可能会出现更多错误,但让我们关注第一个:P 实用程序.py import math def calculate_circle_area(radius): """ :param radius: :return: """ area = math.pi * (radius ** 2)
import math
def calculate_circle_area(radius):
"""
:param radius:
:return:
"""
area = math.pi * (radius ** 2)
return area
main.py
import utilities
def main():
float(input("enter the radius of a circle in cm:"))
area = utilities.calculate_circle_area(radius)
print("the area of the circle is:", area)
float(input("enter radius of sphere in cm:"))
volume = utilities.calculate_sphere_volume(radius)
print("the volume of the sphere is:", volume)
bmi = utilities.calculate_bmi()
print("the body mass index is:", bmi)
hypotenuse = utilities.calculate_hypotenuse()
print("the hypotenuse length of the tight triangle is:", hypotenuse)
if __name__ == "__main__":
main()
您需要先启动一个变量,然后才能传递它。在您的例子中,
radius
变量。即使在您共享的图像中,错误也会显示第6行
导入实用程序
def main():
半径=浮动(输入(“以厘米为单位输入圆的半径”)#此项为必填项,否则会出现该参考错误
面积=实用工具。计算圆面积(半径)
打印(“圆的面积为:”,面积)
半径=浮动(输入(“以厘米为单位输入球体半径:”)
体积=实用程序。计算球体体积(半径)
打印(“球体的体积为:”,体积)
bmi=实用程序。计算\u bmi()
打印(“体重指数为:”,bmi)
斜边=实用工具。计算斜边()
打印(“紧三角形的斜边长度为:”,斜边)
如果名称=“\uuuuu main\uuuuuuuu”:
main()
您的意思是:“半径=浮动(输入(“输入…”)”吗?