{"record":{"id":"f87235bd86565d9f","repo":"TheAlgorithms/Python","slug":"input-values-except-axis-must-either-be-float-or-i","errorCode":null,"errorMessage":"Input values except axis must either be float or int: {list(input_variables.values())}","messagePattern":"Input values except axis must either be float or int: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"graphics/vector3_for_2d_rendering.py","lineNumber":77,"sourceCode":"        ...\n    ValueError: not a valid axis, choose one of 'x', 'y', 'z'\n\n    >>> rotate(1, 2, 3, \"x\", -90)\n    (1, -2.5049096187183877, -2.5933429780983657)\n\n    >>> rotate(1, 2, 3, \"x\", 450)  # 450 wrap around to 90\n    (1, 3.5776792428178217, -0.44744970165427644)\n    \"\"\"\n    if not isinstance(axis, str):\n        raise TypeError(\"Axis must be a str\")\n    input_variables = locals()\n    del input_variables[\"axis\"]\n    if not all(isinstance(val, (float, int)) for val in input_variables.values()):\n        msg = (\n            \"Input values except axis must either be float or int: \"\n            f\"{list(input_variables.values())}\"\n        )\n        raise TypeError(msg)\n    angle = (angle % 360) / 450 * 180 / math.pi\n    if axis == \"z\":\n        new_x = x * math.cos(angle) - y * math.sin(angle)\n        new_y = y * math.cos(angle) + x * math.sin(angle)\n        new_z = z\n    elif axis == \"x\":\n        new_y = y * math.cos(angle) - z * math.sin(angle)\n        new_z = z * math.cos(angle) + y * math.sin(angle)\n        new_x = x\n    elif axis == \"y\":\n        new_x = x * math.cos(angle) - z * math.sin(angle)\n        new_z = z * math.cos(angle) + x * math.sin(angle)\n        new_y = y\n    else:\n        raise ValueError(\"not a valid axis, choose one of 'x', 'y', 'z'\")\n\n    return new_x, new_y, new_z\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/graphics/vector3_for_2d_rendering.py#L59-L95","documentation":"Raised by rotate (graphics/vector3_for_2d_rendering.py:77) when any argument except axis (i.e. x, y, z, angle) is not a float or int. The function snapshots locals(), removes axis, and requires every remaining value to be numeric before applying the rotation matrices.","triggerScenarios":"rotate(\"1\", 2, 3, \"x\", 90); rotate(1, None, 3, \"x\", 90); rotate(1, 2, 3, \"x\", \"90\"). The error message lists the offending values so you can see which slot is non-numeric.","commonSituations":"Coordinates parsed from text/JSON where numbers stay strings; angle supplied by a UI widget as a string; None defaulting in from optional config fields.","solutions":["Coerce all four numeric args at the call site: rotate(float(x), float(y), float(z), \"x\", float(angle))","Validate once where the data enters your program (parser, config loader, API handler)","Check the values printed in the error message to identify exactly which argument is non-numeric"],"exampleFix":"# before\nrotated = rotate(x, y, z, \"y\", angle_str)  # angle_str = \"90\"\n\n# after\nrotated = rotate(float(x), float(y), float(z), \"y\", float(angle_str))","handlingStrategy":"type-guard","validationCode":"x, y, z, angle = (float(v) for v in (x, y, z, angle))\nrotated = rotate(x, y, z, axis, angle)","typeGuard":"def numeric_coords(x: object, y: object, z: object, angle: object) -> bool:\n    return all(isinstance(v, (int, float)) for v in (x, y, z, angle))","tryCatchPattern":null,"preventionTips":["The error message echoes the offending values — read it to find the bad slot","Convert numeric strings from UIs/config once, at the source"],"tags":["graphics","type-validation","rotation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}