{"record":{"id":"d488d2899b1a2077","repo":"TheAlgorithms/Python","slug":"input-values-must-either-be-float-or-int-list-lo","errorCode":null,"errorMessage":"Input values must either be float or int: {list(locals().values())}","messagePattern":"Input values must either be float or int: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"graphics/vector3_for_2d_rendering.py","lineNumber":32,"sourceCode":"    x: float, y: float, z: float, scale: float, distance: float\n) -> tuple[float, float]:\n    \"\"\"\n    Converts 3d point to a 2d drawable point\n\n    >>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0)\n    (7.6923076923076925, 15.384615384615385)\n\n    >>> convert_to_2d(1, 2, 3, 10, 10)\n    (7.6923076923076925, 15.384615384615385)\n\n    >>> convert_to_2d(\"1\", 2, 3, 10, 10)  # '1' is str\n    Traceback (most recent call last):\n        ...\n    TypeError: Input values must either be float or int: ['1', 2, 3, 10, 10]\n    \"\"\"\n    if not all(isinstance(val, (float, int)) for val in locals().values()):\n        msg = f\"Input values must either be float or int: {list(locals().values())}\"\n        raise TypeError(msg)\n    projected_x = ((x * distance) / (z + distance)) * scale\n    projected_y = ((y * distance) / (z + distance)) * scale\n    return projected_x, projected_y\n\n\ndef rotate(\n    x: float, y: float, z: float, axis: str, angle: float\n) -> tuple[float, float, float]:\n    \"\"\"\n    rotate a point around a certain axis with a certain angle\n    angle can be any integer between 1, 360 and axis can be any one of\n    'x', 'y', 'z'\n\n    >>> rotate(1.0, 2.0, 3.0, 'y', 90.0)\n    (3.130524675073759, 2.0, 0.4470070007889556)\n\n    >>> rotate(1, 2, 3, \"z\", 180)\n    (0.999736015495891, -2.0001319704760485, 3)","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/graphics/vector3_for_2d_rendering.py#L14-L50","documentation":"Raised by convert_to_2d (graphics/vector3_for_2d_rendering.py:32) when any of its five arguments (x, y, z, distance, scale) is not a float or int. The function performs 3D-to-2D perspective projection arithmetic, so all five values must be numeric before the projection formulas run.","triggerScenarios":"convert_to_2d(\"1\", 2, 3, 10, 10) — one string poisons all inputs; also None, lists, or bools (bool passes the check since bool subclasses int, which can silently produce 1/0 coordinates).","commonSituations":"Reading coordinates from JSON/CSV where numbers arrive as strings; passing values straight from a GUI form or argparse without float(); passing Decimal or Fraction objects that are numeric but not int/float instances.","solutions":["Convert each argument at the call site: convert_to_2d(float(x), float(y), float(z), float(distance), float(scale))","Sanitize incoming data once at the boundary (parser/config loader), not at every call","If using Decimal/Fraction, convert to float first — the function only accepts the built-in numeric types"],"exampleFix":"# before\npoint_2d = convert_to_2d(row[\"x\"], row[\"y\"], row[\"z\"], distance, scale)  # row values are str\n\n# after\npoint_2d = convert_to_2d(\n    float(row[\"x\"]), float(row[\"y\"]), float(row[\"z\"]),\n    float(distance), float(scale),\n)","handlingStrategy":"type-guard","validationCode":"x, y, z, distance, scale = (float(v) for v in (x, y, z, distance, scale))\nprojected = convert_to_2d(x, y, z, distance, scale)","typeGuard":"def all_numeric(*vals: object) -> bool:\n    return all(isinstance(v, (int, float)) and not isinstance(v, bool) for v in vals)","tryCatchPattern":"try:\n    p = convert_to_2d(x, y, z, d, s)\nexcept TypeError as exc:\n    raise ValueError(f\"bad 3D point data: {exc}\") from exc","preventionTips":["Coerce to float where data enters your program, not per call","Reject bool explicitly if 1/0-as-bool would silently distort coordinates"],"tags":["graphics","type-validation","projection"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}