{"record":{"id":"7b779bb7378c1641","repo":"TheAlgorithms/Python","slug":"please-enter-an-integer-greater-than-0","errorCode":null,"errorMessage":"Please enter an integer greater than 0","messagePattern":"Please enter an integer greater than 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"project_euler/problem_069/sol1.py","lineNumber":48,"sourceCode":"    Algorithm:\n    1. Precompute φ(k) for all natural k, k <= n using product formula (wikilink below)\n    https://en.wikipedia.org/wiki/Euler%27s_totient_function#Euler's_product_formula\n\n    2. Find k/φ(k) for all k ≤ n and return the k that attains maximum\n\n    >>> solution(10)\n    6\n\n    >>> solution(100)\n    30\n\n    >>> solution(9973)\n    2310\n\n    \"\"\"\n\n    if n <= 0:\n        raise ValueError(\"Please enter an integer greater than 0\")\n\n    phi = list(range(n + 1))\n    for number in range(2, n + 1):\n        if phi[number] == number:\n            phi[number] -= 1\n            for multiple in range(number * 2, n + 1, number):\n                phi[multiple] = (phi[multiple] // number) * (number - 1)\n\n    answer = 1\n    for number in range(1, n + 1):\n        if (answer / phi[answer]) < (number / phi[number]):\n            answer = number\n\n    return answer\n\n\nif __name__ == \"__main__\":\n    print(solution())","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/project_euler/problem_069/sol1.py#L30-L66","documentation":"Raised by solution() in project_euler/problem_069/sol1.py when n <= 0. The function builds a sieve-based totient table phi = list(range(n + 1)); a non-positive n makes the table (and the max n/phi(n) search over 1..n) meaningless, so it refuses immediately. Note n is not type-checked here, so a float like 10.5 would cause a different failure downstream.","triggerScenarios":"solution(0), solution(-10), or callers forwarding a computed bound that collapsed to 0 (e.g. solution(limit - delta) where delta >= limit).","commonSituations":"Parameterized test sweeps that include 0 or negative bounds; config values parsed as 0 when a variable is unset; arithmetic on limits (subtraction/rounding) producing <= 0.","solutions":["Pass a positive integer bound: solution(10), solution(1000000).","Guard computed bounds at the call site: if bound <= 0: raise/skip.","Fix the upstream variable that produced 0 (missing env var, empty input)."],"exampleFix":"# before\nbound = limit - offset  # can be <= 0\nbest = solution(bound)\n\n# after\nif bound <= 0:\n    raise ValueError(f\"bound must be positive, got {bound}\")\nbest = solution(bound)","handlingStrategy":"validation","validationCode":"if not isinstance(n, int) or n <= 0:\n    raise ValueError(f\"n must be a positive int, got {n!r}\")\nsolution(n)","typeGuard":"def is_positive_int(value) -> bool:\n    return isinstance(value, int) and value > 0","tryCatchPattern":"try:\n    answer = solution(n)\nexcept ValueError as e:\n    if \"greater than 0\" in str(e):\n        answer = None  # or a sensible default for your use case\n    else:\n        raise","preventionTips":["Validate bounds > 0 before calling; the function only checks the lower bound itself.","Note there is no type check here: floats would fail differently downstream.","Audit computed bounds (limit - offset) for zero/negative results."],"tags":["project-euler","validation","valueerror","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}