{"record":{"id":"42c189a23e24c5ee","repo":"TheAlgorithms/Python","slug":"in-malus-law-the-angle-is-in-the-range-0-360-degr","errorCode":null,"errorMessage":"In Malus Law, the angle is in the range 0-360 degrees","messagePattern":"In Malus Law, the angle is in the range 0-360 degrees","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"physics/malus_law.py","lineNumber":72,"sourceCode":"    >>> round(malus_law(10,900),2)\n    Traceback (most recent call last):\n        ...\n    ValueError: In Malus Law, the angle is in the range 0-360 degrees\n    >>> round(malus_law(-100,900),2)\n    Traceback (most recent call last):\n        ...\n    ValueError: The value of intensity cannot be negative\n    >>> round(malus_law(100,180),2)\n    100.0\n    >>> round(malus_law(100,360),2)\n    100.0\n    \"\"\"\n\n    if initial_intensity < 0:\n        raise ValueError(\"The value of intensity cannot be negative\")\n        # handling of negative values of initial intensity\n    if angle < 0 or angle > 360:\n        raise ValueError(\"In Malus Law, the angle is in the range 0-360 degrees\")\n        # handling of values out of allowed range\n    return initial_intensity * (math.cos(math.radians(angle)) ** 2)\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod(name=\"malus_law\")\n","sourceCodeStart":54,"sourceCodeEnd":81,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/malus_law.py#L54-L81","documentation":"Raised by malus_law(initial_intensity, angle) when angle < 0 or angle > 360. The formula I = I0*cos^2(radians(angle)) uses degrees over one full turn; inputs outside [0, 360] are rejected rather than wrapped. This check runs only after the negative-intensity check passes.","triggerScenarios":"malus_law(100, -30) or malus_law(100, 400); supplying radians (e.g. 6.28) works numerically but is wrong physics — degrees are expected.","commonSituations":"Passing radians instead of degrees; angles accumulated by integration that exceed 360; negative angles from clockwise-rotation conventions not normalized.","solutions":["Normalize the angle into [0, 360]: angle % 360 (and add 360 first for negatives).","Convert radians with math.degrees() before calling.","Pre-validate 0 <= angle <= 360 alongside intensity >= 0."],"exampleFix":"# before\nmalus_law(100, -30)   # ValueError\nmalus_law(100, 1.57)  # wrong: radians silently accepted as degrees\n\n# after\nmalus_law(100, (-30) % 360)          # 330\nmalus_law(100, math.degrees(1.57))    # ~90","handlingStrategy":"validation","validationCode":"angle_deg = angle % 360  # normalizes negatives and >360 wraps\nif not (0 <= angle_deg <= 360):\n    raise ValueError('angle normalization failed')\nmalus_law(initial_intensity, angle_deg)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["malus_law expects degrees, not radians — convert with math.degrees().","Normalize accumulated/signed angles with angle % 360 before calling.","The intensity check fires first, so validate both inputs together."],"tags":["physics","optics","polarization","angle-range","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}