【发布时间】:2020-08-05 22:58:50
【问题描述】:
这是我不断出错的代码。编写一个程序,提示用户输入圆心和圆上一个点的坐标。然后程序应该输出圆的半径、直径、周长和面积。这是python的介绍类。
def main():
x1 = eval(input("enter x1"))
y1 = eval(input("enter y1"))
x2 = eval(input("enter x2"))
y2 = eval(input("enter y2"))
print((x2-x1)**2 + (y2-y1)**2)*(1/2)
pi = 3.14
c = float(input("input the circumference of the circle :"))
print("the diameter of the circle with circumference" + str(c) + " is: " + str(2*pi*r))
r = float(input("input the radius of the circle :"))
print("the area of the circle with radius" + str(r) + " is: " + str(pi*r^2))
print("The radius,diameter,circumference,and area")
main()
【问题讨论】:
-
你有什么错误?
-
c = float("input the circumference of the circle :")应该是c = float(input("input the circumference of the circle :")),r=也是如此 -
我的错误是我的圆周给了我错误
-
您的
print("the diameter of the circle with circumference" + str(c) + " is: " + str(2*pi*r))语句在定义之前使用了“r”。 -
您的代码存在不少于 4 种类型的错误,完整列表请参见我的答案。
标签: python