{"record":{"id":"b795eccb5fa54353","repo":"geekcomputers/Python","slug":"parameter-n-must-be-greater-or-equal-to-one","errorCode":null,"errorMessage":"Parameter n must be greater or equal to one.","messagePattern":"Parameter n must be greater or equal to one\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"A solution to project euler problem 3.py","lineNumber":43,"sourceCode":"    >>> solution(-17)\n    Traceback (most recent call last):\n        ...\n    ValueError: Parameter n must be greater or equal to one.\n    >>> solution([])\n    Traceback (most recent call last):\n        ...\n    TypeError: Parameter n must be int or passive of cast to int.\n    >>> solution(\"asd\")\n    Traceback (most recent call last):\n        ...\n    TypeError: Parameter n must be int or passive of cast to int.\n    \"\"\"\n    try:\n        n = int(n)\n    except (TypeError, ValueError):\n        raise TypeError(\"Parameter n must be int or passive of cast to int.\")\n    if n <= 0:\n        raise ValueError(\"Parameter n must be greater or equal to one.\")\n\n    i = 2\n    ans = 0\n\n    if n == 2:\n        return 2\n\n    while n > 2:\n        while n % i != 0:\n            i += 1\n\n        ans = i\n\n        while n % i == 0:\n            n = n / i\n\n        i += 1\n","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/geekcomputers/Python/blob/40f4cd2652d75ef8e49d76e5c4d431d458712719/A solution to project euler problem 3.py#L25-L61","documentation":"Raised by solution() when the input integer n is less than or equal to zero. Prime factorization is only defined for positive integers, so the function rejects n <= 0 after the int cast succeeds.","triggerScenarios":"Calling solution(0), solution(-5), or solution(\"-3\") — int(\"-3\") casts fine, then the n <= 0 check fires.","commonSituations":"Off-by-one bugs in loops calling solution with 0, parsing negative user input, or defaulting a parameter to 0.","solutions":["Pass a positive integer >= 1","Guard loops so n starts at 1 or 2","Validate user input for positivity before calling"],"exampleFix":"// before\nsolution(0)\n// after\nsolution(600851475143)","handlingStrategy":"validation","validationCode":"n = int(n)\nif n <= 0:\n    raise ValueError('n must be >= 1')\nsolution(n)","typeGuard":"def is_positive_int(n) -> TypeGuard[int]:\n    return isinstance(n, int) and not isinstance(n, bool) and n > 0","tryCatchPattern":"try:\n    solution(n)\nexcept ValueError as e:\n    if 'greater or equal to one' in str(e):\n        n = abs(n) or 1\n    else:\n        raise","preventionTips":["Validate positivity before calling factorization routines","Clamp loop variables to start at 1 or 2","Reject zero/negative user input explicitly"],"tags":["python","value-error","input-validation"],"backgroundTag":"argument-out-of-range","analyzedSha":"40f4cd2652d75ef8e49d76e5c4d431d458712719","analyzedAt":"2026-08-27T11:12:20.313Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}