{"record":{"id":"1867ddcb73b57bd7","repo":"TheAlgorithms/Python","slug":"value-should-be-between-0-and-1","errorCode":null,"errorMessage":"value should be between 0 and 1","messagePattern":"value should be between 0 and 1","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"conversions/rgb_hsv_conversion.py","lineNumber":49,"sourceCode":"    >>> hsv_to_rgb(240, 1, 1)\n    [0, 0, 255]\n    >>> hsv_to_rgb(300, 1, 1)\n    [255, 0, 255]\n    >>> hsv_to_rgb(180, 0.5, 0.5)\n    [64, 128, 128]\n    >>> hsv_to_rgb(234, 0.14, 0.88)\n    [193, 196, 224]\n    >>> hsv_to_rgb(330, 0.75, 0.5)\n    [128, 32, 80]\n    \"\"\"\n    if hue < 0 or hue > 360:\n        raise Exception(\"hue should be between 0 and 360\")\n\n    if saturation < 0 or saturation > 1:\n        raise Exception(\"saturation should be between 0 and 1\")\n\n    if value < 0 or value > 1:\n        raise Exception(\"value should be between 0 and 1\")\n\n    chroma = value * saturation\n    hue_section = hue / 60\n    second_largest_component = chroma * (1 - abs(hue_section % 2 - 1))\n    match_value = value - chroma\n\n    if hue_section >= 0 and hue_section <= 1:\n        red = round(255 * (chroma + match_value))\n        green = round(255 * (second_largest_component + match_value))\n        blue = round(255 * (match_value))\n    elif hue_section > 1 and hue_section <= 2:\n        red = round(255 * (second_largest_component + match_value))\n        green = round(255 * (chroma + match_value))\n        blue = round(255 * (match_value))\n    elif hue_section > 2 and hue_section <= 3:\n        red = round(255 * (match_value))\n        green = round(255 * (chroma + match_value))\n        blue = round(255 * (second_largest_component + match_value))","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/rgb_hsv_conversion.py#L31-L67","documentation":"Raised by hsv_to_rgb() in conversions/rgb_hsv_conversion.py when value < 0 or value > 1. Here 'value' is HSV brightness (V), expected as a fraction in [0, 1]; percentage inputs are the usual culprit. Raised as bare Exception.","triggerScenarios":"Calling hsv_to_rgb(300, 1, 100) (percent), hsv_to_rgb(0, 0, -0.1), or feeding lightness/brightness from a 0..100 UI control unconverted.","commonSituations":"Brightness sliders in 0..100 range; confusing HSV 'value' with HSL 'lightness' or with 8-bit 0..255 scale; importing colors from formats that use percentages.","solutions":["Convert 0..100 scales to fractions: value / 100.","Clamp: max(0.0, min(1.0, value)).","If your source is HSL, convert HSL->HSV first rather than passing lightness as value."],"exampleFix":"# before\nhsv_to_rgb(300, 1, 100)  # Exception: value should be between 0 and 1\n\n# after\nhsv_to_rgb(300, 1, 100 / 100)  # [255, 0, 255]","handlingStrategy":"validation","validationCode":"if not 0 <= value <= 1:\n    value = max(0.0, min(1.0, value / 100 if value > 1 else value))\nhsv_to_rgb(hue, saturation, value)","typeGuard":"def valid_v_brightness(v: float) -> bool:\n    return 0 <= v <= 1","tryCatchPattern":"try:\n    hsv_to_rgb(h, s, v)\nexcept Exception as e:  # bare Exception from the library\n    if 'value should be' in str(e):\n        hsv_to_rgb(h, s, v / 100)  # percentage input\n    else:\n        raise","preventionTips":["HSV V is a 0..1 fraction, not 0..255 and not 0..100","Convert HSL lightness to HSV value before calling","Clamp slider outputs from 0..100 widgets"],"tags":["python","validation","range","color","conversion"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}