python-3.x 涉及圆面积的逻辑错误

sr4lhrrt  于 2023-01-18  发布在  Python
关注(0)|答案(5)|浏览(183)

在python中,不知道为什么,它是某种逻辑错误,因为它不是正确的数字,我应该创建一个算法,从半径计算圆的面积。
My python code

f4t66c6m

f4t66c6m1#

math.sqrt()

表示计算平方根计算(√)。您只需要

r * r

来解决这个问题。

nxagd54h

nxagd54h2#

用这个

area = (22/7)((r)**2)

希望能有所帮助。

sh7euo9m

sh7euo9m3#

不需要定义任何函数就可以计算圆的面积。
试试这个:

pi = 3.142
r = float(input("enter your radius of circle: "))

Area = pi * r * r

print("Area of the circle is: ", area)
w6lpcovy

w6lpcovy4#

下面是求圆的半径和周长

# Name
Name = raw_input("Enter Your Name: ")

# Give area for the circle
Area = input("Enter Area of the circle: ")

PI = 3.14

# Calculation of radius and circumference
R = (Area / PI )**0.5
C = (2 * PI * R)

print "Area of the Circle = %.2f"%Area 
print "Radius of Circle = %.2f"%R
print "Circumference of Circle = %.2f"%C
ejk8hzay

ejk8hzay5#

def computeArea(val):
    area=pi*(val**2)
    return area
pi=3.14
inputText=input("does the question give a diameter(d) or radius(r)")
if inputText=='r':
    radius=int(input("what is the radius"))
    print(f"area of the circle is {computeArea(radius)}")
elif inputText=='d':
    D=int(input("what is the diameter"))
    r=(D/2)
    area=computeArea(r)
    print(f"area of the circle is {computeArea(r)}")
else:
    print("You entered an incorrect value you can either type r for radius or d for diameter")

相关问题