{"record":{"id":"4cd5f5408547a1f3","repo":"TheAlgorithms/Python","slug":"parameter-n-must-be-greater-than-or-equal-to-one-4cd5f5","errorCode":null,"errorMessage":"Parameter n must be greater than or equal to one.","messagePattern":"Parameter n must be greater than or equal to one\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"project_euler/problem_005/sol1.py","lineNumber":53,"sourceCode":"    Traceback (most recent call last):\n        ...\n    ValueError: Parameter n must be greater than or equal to one.\n    >>> solution([])\n    Traceback (most recent call last):\n        ...\n    TypeError: Parameter n must be int or castable to int.\n    >>> solution(\"asd\")\n    Traceback (most recent call last):\n        ...\n    TypeError: Parameter n must be int or castable to int.\n    \"\"\"\n\n    try:\n        n = int(n)\n    except TypeError, ValueError:\n        raise TypeError(\"Parameter n must be int or castable to int.\")\n    if n <= 0:\n        raise ValueError(\"Parameter n must be greater than or equal to one.\")\n    i = 0\n    while 1:\n        i += n * (n - 1)\n        nfound = 0\n        for j in range(2, n):\n            if i % j != 0:\n                nfound = 1\n                break\n        if nfound == 0:\n            if i == 0:\n                i = 1\n            return i\n    return None\n\n\nif __name__ == \"__main__\":\n    print(f\"{solution() = }\")\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/project_euler/problem_005/sol1.py#L35-L71","documentation":"Documented ValueError from project_euler/problem_005/sol1.py:solution when n <= 0 after int conversion; the smallest-multiple (LCM 1..n) search requires n >= 1. CAVEAT: the file's py2 except syntax makes it a SyntaxError under Python 3 at import, so this ValueError cannot fire until the syntax is fixed at line 51.","triggerScenarios":"After the fix: solution(0) or solution(-3). Today: any import under Python 3 raises SyntaxError first.","commonSituations":"n=0 sentinels meaning 'use default'; range loops starting at 0 in benchmarks; the same py3 migration breakage shared with errors 837/839.","solutions":["Fix the except clause at project_euler/problem_005/sol1.py:51 to except (TypeError, ValueError):","Pass n >= 1 (n=1 returns 1, n=20 gives the classic answer 232792560).","Skip non-positive bounds in sweeps rather than calling with them.","Catch ValueError in generic drivers that enumerate n."],"exampleFix":"# before\nfor n in range(0, 21):\n    solution(n)  # n=0 raises\n\n# after\nfor n in range(1, 21):\n    solution(n)","handlingStrategy":"validation","validationCode":"n = int(n)\nif n < 1:\n    raise ValueError('n must be >= 1')\nsolution(n)","typeGuard":"def is_valid_lcm_bound(n) -> bool:\n    return isinstance(n, int) and not isinstance(n, bool) and n >= 1","tryCatchPattern":"try:\n    solution(n)\nexcept ValueError:\n    ...","preventionTips":["Do not use 0 as a default/sentinel bound.","Start enumeration ranges at 1.","Fix the module's py2 syntax before depending on its errors."],"tags":["python-euler","python2-syntax","valueerror","validation","lcm"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}