提问人:AJHedges 提问时间:9/28/2023 最后编辑:S3DEVAJHedges 更新时间:9/28/2023 访问量:58
使用直径输入/Def 函数查找圆的面积 [已关闭]
finding the area of a circle using diameter input / Def functions [closed]
问:
我正在尝试使用直径输入找到以平方为单位的圆的面积。我觉得我离正确不远了。程序打开,但在排除输入后关闭。这是我到目前为止的代码 这是我到目前为止的代码..
def circleArea(diameter_of_the_circle):
radius = diameter / 2
pi = 3.14159
result = pi * radius * radius
return(result)
dt = float(input("\nEnter the diameter of the circle in cms: "))
anwser = circleArea(diameter_of_the_circle)
print("\nThe Area of the circle is:", anwser)
input("\nPress Enter to exit")
答:
0赞
Amir
9/28/2023
#1
您的代码存在几个问题:
- 在函数定义中,参数是 ,然后你有 .什么?
diameter_of_the_circle
radius = diameter / 2
diameter
- 您定义了函数输入,但随后将其用作函数输入。
dt
diameter_of_the_circle
1赞
Libnist
9/28/2023
#2
您忘记使用与输入参数相同的名称。
import math
def circleArea(diameter):
radius = diameter / 2
result = math.pi * radius * radius
return(result)
dt = float(input("\nEnter the diameter of the circle in cms: "))
anwser = circleArea(dt)
print("\nThe Area of the circle is:", anwser)
input("\nPress Enter to exit")
评论
diameter_of_the_circle