{"record":{"id":"e7655928541e2a3a","repo":"TheAlgorithms/Python","slug":"correct-format-for-using-this-script-python-fract","errorCode":null,"errorMessage":"Correct format for using this script: python fractals.py <int:depth_for_fractal>","messagePattern":"Correct format for using this script: python fractals\\.py <int:depth_for_fractal>","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"fractals/sierpinski_triangle.py","lineNumber":75,"sourceCode":"    \"\"\"\n    my_pen.up()\n    my_pen.goto(vertex1[0], vertex1[1])\n    my_pen.down()\n    my_pen.goto(vertex2[0], vertex2[1])\n    my_pen.goto(vertex3[0], vertex3[1])\n    my_pen.goto(vertex1[0], vertex1[1])\n\n    if depth == 0:\n        return\n\n    triangle(vertex1, get_mid(vertex1, vertex2), get_mid(vertex1, vertex3), depth - 1)\n    triangle(vertex2, get_mid(vertex1, vertex2), get_mid(vertex2, vertex3), depth - 1)\n    triangle(vertex3, get_mid(vertex3, vertex2), get_mid(vertex1, vertex3), depth - 1)\n\n\nif __name__ == \"__main__\":\n    if len(sys.argv) != 2:\n        raise ValueError(\n            \"Correct format for using this script: \"\n            \"python fractals.py <int:depth_for_fractal>\"\n        )\n    my_pen = turtle.Turtle()\n    my_pen.ht()\n    my_pen.speed(5)\n    my_pen.pencolor(\"red\")\n\n    vertices = [(-175, -125), (0, 175), (175, -125)]  # vertices of triangle\n    triangle(vertices[0], vertices[1], vertices[2], int(sys.argv[1]))\n    turtle.Screen().exitonclick()\n","sourceCodeStart":57,"sourceCodeEnd":87,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/fractals/sierpinski_triangle.py#L57-L87","documentation":"Raised by the __main__ block of fractals/sierpinski_triangle.py when sys.argv does not contain exactly one argument. The script then draws the Sierpinski triangle with turtle graphics at the given recursion depth. Note the message references 'fractals.py' although the file is sierpinski_triangle.py — a copy-paste leftover that makes the usage string misleading.","triggerScenarios":"Running python sierpinski_triangle.py (no depth), python sierpinski_triangle.py 3 4 (two args), or passing flags like --depth 3 (two args after the flag). Note a non-integer depth such as 'abc' passes the argc check and instead crashes at int(sys.argv[1]) with a different ValueError.","commonSituations":"Users expecting --help or argparse-style flags, running the module with extra arguments, or following the outdated usage text and getting confused by the wrong filename in the message.","solutions":["Run with exactly one integer argument: python sierpinski_triangle.py 3.","If you maintain this script, fix the message to name the real file (or switch to argparse).","Note this only guards the CLI path — importing triangle() directly needs no argv."],"exampleFix":"# before (maintainer fix)\nraise ValueError(\n    \"Correct format for using this script: \"\n    \"python fractals.py <int:depth_for_fractal>\"\n)\n\n# after\nraise SystemExit(\n    \"Usage: python sierpinski_triangle.py <int:depth>\"\n)","handlingStrategy":"validation","validationCode":"if len(sys.argv) != 2:\n    raise SystemExit('Usage: python sierpinski_triangle.py <int:depth>')\ntry:\n    depth = int(sys.argv[1])\nexcept ValueError:\n    raise SystemExit(f'depth must be an integer, got {sys.argv[1]!r}')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer SystemExit/argparse for usage errors — ValueError here implies a library bug it isn't.","Remember turtle scripts need a display; headless CI runs fail separately.","Import triangle() programmatically if you want the algorithm without the CLI."],"tags":["cli","usage-error","graphics","turtle"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}