>>> round(malus_law(10,45),2) 5.0 >>> round(malus_law(100,60),2) 25.0 >>> round(malus_law(50,150),2) 37.5 >>> round(malus_law(75,270),2) 0.0 >>> round(malus_law(10,-900),2) Traceback (most recent call last): ... ValueError: In Malus Law, the angle
(initial_intensity: float, angle: float)
| 38 | |
| 39 | |
| 40 | def malus_law(initial_intensity: float, angle: float) -> float: |
| 41 | """ |
| 42 | >>> round(malus_law(10,45),2) |
| 43 | 5.0 |
| 44 | >>> round(malus_law(100,60),2) |
| 45 | 25.0 |
| 46 | >>> round(malus_law(50,150),2) |
| 47 | 37.5 |
| 48 | >>> round(malus_law(75,270),2) |
| 49 | 0.0 |
| 50 | >>> round(malus_law(10,-900),2) |
| 51 | Traceback (most recent call last): |
| 52 | ... |
| 53 | ValueError: In Malus Law, the angle is in the range 0-360 degrees |
| 54 | >>> round(malus_law(10,900),2) |
| 55 | Traceback (most recent call last): |
| 56 | ... |
| 57 | ValueError: In Malus Law, the angle is in the range 0-360 degrees |
| 58 | >>> round(malus_law(-100,900),2) |
| 59 | Traceback (most recent call last): |
| 60 | ... |
| 61 | ValueError: The value of intensity cannot be negative |
| 62 | >>> round(malus_law(100,180),2) |
| 63 | 100.0 |
| 64 | >>> round(malus_law(100,360),2) |
| 65 | 100.0 |
| 66 | """ |
| 67 | |
| 68 | if initial_intensity < 0: |
| 69 | raise ValueError("The value of intensity cannot be negative") |
| 70 | # handling of negative values of initial intensity |
| 71 | if angle < 0 or angle > 360: |
| 72 | raise ValueError("In Malus Law, the angle is in the range 0-360 degrees") |
| 73 | # handling of values out of allowed range |
| 74 | return initial_intensity * (math.cos(math.radians(angle)) ** 2) |
| 75 | |
| 76 | |
| 77 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected