{"record":{"id":"ccf8ff33e2bd9712","repo":"TheAlgorithms/Python","slug":"invalid-inputs-enter-non-zero-values-with-respect-ccf8ff","errorCode":null,"errorMessage":"Invalid inputs. Enter non zero values with respect to the sign convention.","messagePattern":"Invalid inputs\\. Enter non zero values with respect to the sign convention\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"physics/mirror_formulae.py","lineNumber":77,"sourceCode":"\n\ndef focal_length(distance_of_object: float, distance_of_image: float) -> float:\n    \"\"\"\n    >>> from math import isclose\n    >>> isclose(focal_length(10, 20), 6.66666666666666)\n    True\n    >>> from math import isclose\n    >>> isclose(focal_length(9.5, 6.7), 3.929012346)\n    True\n    >>> focal_length(0, 20)  # doctest: +NORMALIZE_WHITESPACE\n    Traceback (most recent call last):\n        ...\n    ValueError: Invalid inputs. Enter non zero values with respect\n    to the sign convention.\n    \"\"\"\n\n    if distance_of_object == 0 or distance_of_image == 0:\n        raise ValueError(\n            \"Invalid inputs. Enter non zero values with respect to the sign convention.\"\n        )\n    focal_length = 1 / ((1 / distance_of_object) + (1 / distance_of_image))\n    return focal_length\n\n\ndef object_distance(focal_length: float, distance_of_image: float) -> float:\n    \"\"\"\n    >>> from math import isclose\n    >>> isclose(object_distance(30, 20), -60.0)\n    True\n    >>> from math import isclose\n    >>> isclose(object_distance(10.5, 11.7), 102.375)\n    True\n    >>> object_distance(90, 0)  # doctest: +NORMALIZE_WHITESPACE\n    Traceback (most recent call last):\n        ...\n    ValueError: Invalid inputs. Enter non zero values with respect","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/mirror_formulae.py#L59-L95","documentation":"Raised by focal_length(distance_of_object, distance_of_image) in mirror_formulae.py when either distance is exactly 0. The mirror formula f = 1/(1/u + 1/v) needs both reciprocals, so zero is rejected to avoid division by zero. Negative distances are valid under the Cartesian sign convention used for mirrors.","triggerScenarios":"focal_length(0, 20) from the doctest; an object or image located exactly at the mirror pole.","commonSituations":"Zero-initialized ray-tracing parameters; geometry solvers converging to 0.0; sign-convention confusion leading to 0 instead of a small negative value.","solutions":["Ensure both distances are non-zero before calling (negatives allowed).","Initialize optics parameters to non-zero sentinels or make them required.","Catch ValueError to flag the degenerate on-mirror configuration."],"exampleFix":"# before\nfocal_length(0, 20)  # ValueError\n\n# after\nfocal_length(9.5, 6.7)  # 3.929012346","handlingStrategy":"validation","validationCode":"def valid_mirror_distances(*d: float) -> bool:\n    return all(x != 0 for x in d)\n\nif valid_mirror_distances(distance_of_object, distance_of_image):\n    focal_length(distance_of_object, distance_of_image)","typeGuard":null,"tryCatchPattern":"try:\n    focal_length(u, v)\nexcept ValueError:\n    # object or image exactly at the mirror pole; handle degenerate ray here\n    ...","preventionTips":["Only exact zero is rejected; negative distances follow the Cartesian sign convention.","Do not zero-initialize mirror parameters in configs or dataclasses.","Handle the on-pole (distance 0) geometry explicitly in your ray tracer."],"tags":["physics","optics","mirror","zero-check","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}