我写了下面提到的代码,但出现以下错误:
“ ValueError:main的文档字符串的第2行。>>>之后,Circle.circumference缺少空白:'>>> c1 = Circle(2.5)'。
请告诉我如何解决此错误?
班级圈子:
def __init__(self, radius):
"""
>>> c1 = Circle(2.5)
>>> c1.radius
2.5
"""
self.radius = radius
def area(self):
"""
>>> c1 = Circle(2.5)
>>> c1.area()
19.63
"""
a = math.pi * self.radius * self.radius
return round(a,2)
def circumference(self):
"""
>>>c1 = Circle(2.5)
>>>c1.circumference()
15.71
"""
c = 2 * math.pi * self.radius
return round(c,2)
您的代码在这些行的圆周上缺少>>>后的空格:
>>>c1 = Circle(2.5)
>>>c1.circumference()