{"record":{"id":"349a29508f77450f","repo":"TheAlgorithms/Python","slug":"iterations-must-be-done-more-than-0-times-to-play","errorCode":null,"errorMessage":"Iterations must be done more than 0 times to play FizzBuzz","messagePattern":"Iterations must be done more than 0 times to play FizzBuzz","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"dynamic_programming/fizz_buzz.py","lineNumber":45,"sourceCode":"    >>> fizz_buzz(1.5,5)\n    Traceback (most recent call last):\n        ...\n    ValueError: starting number must be\n                             and integer and be more than 0\n    >>> fizz_buzz(1,5.5)\n    Traceback (most recent call last):\n        ...\n    ValueError: iterations must be defined as integers\n    \"\"\"\n    if not isinstance(iterations, int):\n        raise ValueError(\"iterations must be defined as integers\")\n    if not isinstance(number, int) or not number >= 1:\n        raise ValueError(\n            \"\"\"starting number must be\n                         and integer and be more than 0\"\"\"\n        )\n    if not iterations >= 1:\n        raise ValueError(\"Iterations must be done more than 0 times to play FizzBuzz\")\n\n    out = \"\"\n    while number <= iterations:\n        if number % 3 == 0:\n            out += \"Fizz\"\n        if number % 5 == 0:\n            out += \"Buzz\"\n        if 0 not in (number % 3, number % 5):\n            out += str(number)\n\n        # print(out)\n        number += 1\n        out += \" \"\n    return out\n\n\nif __name__ == \"__main__\":\n    import doctest","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/dynamic_programming/fizz_buzz.py#L27-L63","documentation":"Raised by fizz_buzz when iterations is an int but is less than 1 (not iterations >= 1). This is the third and last validation check, so it fires only after the type checks passed — e.g. fizz_buzz(0, 1) or fizz_buzz(-5, 1). The loop 'while number <= iterations' would otherwise never execute, and the library treats zero iterations as invalid usage.","triggerScenarios":"fizz_buzz(0, 1), fizz_buzz(-10, 1); iterations computed as a count that legitimately equals zero (empty range), e.g. fizz_buzz(len(data), 1) with data == [].","commonSituations":"Iteration counts derived from collection sizes that can be empty; config values of 0 meaning 'unlimited' in some systems but rejected here; negative counts from subtraction.","solutions":["Skip the call when the count is zero: if iterations >= 1: fizz_buzz(iterations, 1).","Fix the count computation so it cannot be zero when FizzBuzz output is required.","If 0 means 'no output' in your domain, short-circuit to an empty string instead of calling."],"exampleFix":"# before\nout = fizz_buzz(len(items), 1)  # empty items -> 0 iterations -> ValueError\n\n# after\nout = fizz_buzz(len(items), 1) if items else ''","handlingStrategy":"validation","validationCode":"if isinstance(iterations, int) and iterations >= 1:\n    out = fizz_buzz(iterations, number)\nelse:\n    out = ''","typeGuard":"def is_positive_int(value: object) -> bool:\n    return isinstance(value, int) and not isinstance(value, bool) and value >= 1","tryCatchPattern":"try:\n    out = fizz_buzz(iterations, number)\nexcept ValueError as exc:\n    if 'more than 0 times' in str(exc):\n        out = ''  # zero iterations -> empty output\n    else:\n        raise","preventionTips":["Short-circuit empty ranges before calling loop-count-driven APIs.","Treat counts derived from collection sizes as potentially zero.","Distinguish 'zero means skip' from 'zero is invalid' in your own config semantics."],"tags":["python","input-validation","boundary-check","dynamic-programming"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}