{"record":{"id":"575b347c2338f529","repo":"TheAlgorithms/Python","slug":"parameter-n-must-be-greater-than-or-equal-to-one-575b34","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_003/sol3.py","lineNumber":50,"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 = 2\n    ans = 0\n    if n == 2:\n        return 2\n    while n > 2:\n        while n % i != 0:\n            i += 1\n        ans = i\n        while n % i == 0:\n            n = n // i\n        i += 1\n    return int(ans)\n\n\nif __name__ == \"__main__\":\n    print(f\"{solution() = }\")\n","sourceCodeStart":32,"sourceCodeEnd":67,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/project_euler/problem_003/sol3.py#L32-L67","documentation":"Documented ValueError from project_euler/problem_003/sol3.py:solution when n <= 0 after int conversion; the incremental factor-finding loop assumes n >= 1. CAVEAT: unreachable in the shipped file because 'except TypeError, ValueError:' is Python 2 syntax - Python 3 raises SyntaxError at import before this branch can execute.","triggerScenarios":"After the syntax fix: solution(0) or solution(-100). Today: importing project_euler/problem_003/sol3.py under Python 3 exits with SyntaxError.","commonSituations":"Zero default parameters in generic runners; negative n from unvalidated CLI args; the same py3 migration that breaks all three problem_003 solutions at once, which can mask this check entirely.","solutions":["Fix the except clause at project_euler/problem_003/sol3.py:48.","Pass n >= 1.","Validate CLI/user input before the call (positive-integer check).","Catch ValueError in enumerating drivers."],"exampleFix":"# before\nsolution(-100)\n\n# after\nif int(n) > 0:\n    print(solution(n))","handlingStrategy":"validation","validationCode":"n = int(n)\nif n < 1:\n    raise ValueError('n must be >= 1')\nsolution(n)","typeGuard":"def is_valid_factorization_input(n) -> bool:\n    return isinstance(n, int) and n >= 1","tryCatchPattern":"try:\n    solution(n)\nexcept ValueError:\n    ...","preventionTips":["Validate CLI args for positivity before calling.","Fix the py2 syntax or the module never imports under py3.","Avoid 0-default parameters in generic runners."],"tags":["python-euler","python2-syntax","valueerror","validation","prime-factorization"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}