Doctest使用python检查圆的半径,面积和周长

问题描述 投票:0回答:1

我写了下面提到的代码,但出现以下错误:

“ 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)
python python-3.x doctest
1个回答
0
投票

您的代码在这些行的圆周上缺少>>>后的空格:

    >>>c1 = Circle(2.5)
    >>>c1.circumference()
© www.soinside.com 2019 - 2024. All rights reserved.