{"record":{"id":"9f889bcfd37cdbef","repo":"TheAlgorithms/Python","slug":"starting-number-must-be-a","errorCode":null,"errorMessage":"starting number must be\n                         and integer and be more than 0","messagePattern":"starting number must be\n                         and integer and be more than 0","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"dynamic_programming/fizz_buzz.py","lineNumber":40,"sourceCode":"                             and integer and be more than 0\n    >>> fizz_buzz(10,-5)\n    Traceback (most recent call last):\n        ...\n    ValueError: Iterations must be done more than 0 times to play FizzBuzz\n    >>> 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 += \" \"","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/dynamic_programming/fizz_buzz.py#L22-L58","documentation":"Raised by fizz_buzz when the second parameter, the starting number, is either not an int or is less than 1. The check is isinstance(number, int) or not number >= 1, so fizz_buzz(10, 0), fizz_buzz(10, -3), and fizz_buzz(10, 2.5) all raise. The message text is a triple-quoted string with embedded indentation ('and integer' typo included), so the raised message spans multiple lines.","triggerScenarios":"fizz_buzz(10, 0) or any start < 1; fizz_buzz(10, '1') or fizz_buzz(10, 1.0) with a non-int type; note the parameter order is (iterations, number), so swapped arguments like fizz_buzz(1, 10) meaning 'start at 1, 10 iterations' actually raise here.","commonSituations":"Confusing the parameter order (iterations first, starting number second); zero-based loop counters passed as start values; string values from user input not converted to int.","solutions":["Confirm argument order: fizz_buzz(iterations, number) — total iterations first, then start >= 1.","Pass an int start value of at least 1: fizz_buzz(100, 1) for classic FizzBuzz.","Coerce untrusted input: number = int(number) with a >= 1 check before the call."],"exampleFix":"# before\nfizz_buzz(1, 100)  # swapped args: start=100 ok but iterations=1; fizz_buzz(100, 0) -> ValueError\n\n# after\nfizz_buzz(100, 1)  # 100 iterations starting at 1","handlingStrategy":"type-guard","validationCode":"if not isinstance(number, int) or number < 1:\n    raise ValueError('starting number must be an integer >= 1')\nout = fizz_buzz(iterations, number)","typeGuard":"def is_valid_start(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 'starting number' in str(exc):\n        out = fizz_buzz(iterations, 1)  # restart from 1\n    else:\n        raise","preventionTips":["Memorize the parameter order: fizz_buzz(iterations, number) — count first, start second.","Never pass zero-based loop counters as the starting number.","Write a signature wrapper in your codebase with keyword arguments to avoid order mistakes."],"tags":["python","input-validation","argument-order","dynamic-programming"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}