{"record":{"id":"99bdc96dd790886d","repo":"TheAlgorithms/Python","slug":"not-a-valid-axis-choose-one-of-x-y-z","errorCode":null,"errorMessage":"not a valid axis, choose one of 'x', 'y', 'z'","messagePattern":"not a valid axis, choose one of 'x', 'y', 'z'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"graphics/vector3_for_2d_rendering.py","lineNumber":92,"sourceCode":"            \"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\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n    print(f\"{convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) = }\")\n    print(f\"{rotate(1.0, 2.0, 3.0, 'y', 90.0) = }\")\n","sourceCodeStart":74,"sourceCodeEnd":103,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/graphics/vector3_for_2d_rendering.py#L74-L103","documentation":"Raised by rotate (graphics/vector3_for_2d_rendering.py:92) when axis is a string but not one of 'x', 'y', 'z'. The function dispatches on the axis value with if/elif branches; the final else branch rejects anything else.","triggerScenarios":"rotate(1, 2, 3, \"n\", 90); rotate(1, 2, 3, \"X\", 90) — uppercase fails because matching is case-sensitive; rotate(1, 2, 3, \"xy\", 90).","commonSituations":"User-typed axis names with different case or whitespace ('X', ' x '); localization or alternative naming ('horizontal', 'z-axis'); config typos.","solutions":["Normalize the axis before calling: axis = axis.strip().lower() and verify membership in {'x','y','z'}","Fix the literal to a lowercase 'x', 'y', or 'z'","Constrain UI/config axis fields to a choice list so invalid values cannot reach the library"],"exampleFix":"# before\nrotated = rotate(1, 2, 3, \"X\", 90)  # uppercase -> ValueError\n\n# after\naxis = \"X\".strip().lower()\nif axis not in {\"x\", \"y\", \"z\"}:\n    raise ValueError(f\"unknown axis {axis!r}\")\nrotated = rotate(1, 2, 3, axis, 90)","handlingStrategy":"validation","validationCode":"axis = axis.strip().lower() if isinstance(axis, str) else axis\nif axis not in {\"x\", \"y\", \"z\"}:\n    raise ValueError(f\"axis must be 'x', 'y' or 'z', got {axis!r}\")\nrotated = rotate(x, y, z, axis, angle)","typeGuard":null,"tryCatchPattern":"try:\n    rotated = rotate(x, y, z, axis, angle)\nexcept ValueError:\n    axis = \"z\"  # or surface an error to the user","preventionTips":["Normalize case/whitespace on axis input at the boundary","Restrict axis fields in forms/config to a fixed choice set"],"tags":["graphics","input-validation","rotation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}