{"record":{"id":"22022085f108cdca","repo":"TheAlgorithms/Python","slug":"length-must-be-a-positive","errorCode":null,"errorMessage":"Length must be a positive.","messagePattern":"Length must be a positive\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/dodecahedron.py","lineNumber":36,"sourceCode":"\n    :param edge: length of the edge of the dodecahedron\n    :type edge: float\n    :return: the surface area of the dodecahedron as a float\n\n\n    Tests:\n    >>> dodecahedron_surface_area(5)\n    516.1432201766901\n    >>> dodecahedron_surface_area(10)\n    2064.5728807067603\n    >>> dodecahedron_surface_area(-1)\n    Traceback (most recent call last):\n      ...\n    ValueError: Length must be a positive.\n    \"\"\"\n\n    if edge <= 0 or not isinstance(edge, int):\n        raise ValueError(\"Length must be a positive.\")\n    return 3 * ((25 + 10 * (5 ** (1 / 2))) ** (1 / 2)) * (edge**2)\n\n\ndef dodecahedron_volume(edge: float) -> float:\n    \"\"\"\n    Calculates the volume of a regular dodecahedron\n    v = ((15 + (7 * (5** (1 / 2)))) / 4) * (e**3)\n    where:\n    v --> is the volume of the dodecahedron\n    e --> is the length of the edge\n    reference-->\"Dodecahedron\" Study.com\n    <https://study.com/academy/lesson/dodecahedron-volume-surface-area-formulas.html>\n\n    :param edge: length of the edge of the dodecahedron\n    :type edge: float\n    :return: the volume of the dodecahedron as a float\n\n    Tests:","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/dodecahedron.py#L18-L54","documentation":"Raised by dodecahedron_surface_area() in maths/dodecahedron.py when edge <= 0 or edge is not an int. A regular dodecahedron's surface area 3*sqrt(25+10*sqrt(5))*e^2 only makes sense for a positive edge length, so the function validates it up front. Note the guard is stricter than the message implies: it also rejects floats, so dodecahedron_surface_area(2.5) raises even though 2.5 is a positive length.","triggerScenarios":"Calling dodecahedron_surface_area(-1), dodecahedron_surface_area(0), or dodecahedron_surface_area(5.0) / any float edge. The guard is edge <= 0 or not isinstance(edge, int).","commonSituations":"Edge lengths computed from geometry that are naturally floats (hypotenuse, scaling factors); CSV/JSON numeric input parsed as float; negative values from a subtraction; bool edges (True passes isinstance int and equals 1).","solutions":["Pass an int edge, or verify whole-number values first: int(edge) if edge == int(edge).","If you need fractional edge lengths, compute the formula directly with floats: 3 * ((25 + 10 * 5**0.5) ** 0.5) * edge**2.","Fix upstream units so edge lengths are integral (e.g. work in millimetres instead of metres)."],"exampleFix":"# before\ndodecahedron_surface_area(2.5)  # ValueError: Length must be a positive.\n\n# after\nedge = 2.5\narea = 3 * ((25 + 10 * 5 ** 0.5) ** 0.5) * edge ** 2  # float formula\n# or, for whole values: dodecahedron_surface_area(int(edge))","handlingStrategy":"type-guard","validationCode":"if not isinstance(edge, int) or isinstance(edge, bool) or edge <= 0:\n    raise ValueError(f'edge must be a positive int, got {edge!r}')","typeGuard":"def is_positive_int_edge(e) -> bool:\n    return isinstance(e, int) and not isinstance(e, bool) and e > 0","tryCatchPattern":"try:\n    area = dodecahedron_surface_area(edge)\nexcept ValueError:\n    area = 3 * ((25 + 10 * 5 ** 0.5) ** 0.5) * float(edge) ** 2  # float fallback formula","preventionTips":["This API is int-only despite a float-annotated signature — always pass ints.","Keep a local float formula handy if measurements are fractional."],"tags":["maths","geometry","validation","valueerror","int-only-api"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}