>>> from math import isclose >>> isclose(object_distance(30, 20), -60.0) True >>> from math import isclose >>> isclose(object_distance(10.5, 11.7), 102.375) True >>> object_distance(90, 0) # doctest: +NORMALIZE_WHITESPACE Traceback (most recent call last): .
(focal_length: float, distance_of_image: float)
| 82 | |
| 83 | |
| 84 | def object_distance(focal_length: float, distance_of_image: float) -> float: |
| 85 | """ |
| 86 | >>> from math import isclose |
| 87 | >>> isclose(object_distance(30, 20), -60.0) |
| 88 | True |
| 89 | >>> from math import isclose |
| 90 | >>> isclose(object_distance(10.5, 11.7), 102.375) |
| 91 | True |
| 92 | >>> object_distance(90, 0) # doctest: +NORMALIZE_WHITESPACE |
| 93 | Traceback (most recent call last): |
| 94 | ... |
| 95 | ValueError: Invalid inputs. Enter non zero values with respect |
| 96 | to the sign convention. |
| 97 | """ |
| 98 | |
| 99 | if distance_of_image == 0 or focal_length == 0: |
| 100 | raise ValueError( |
| 101 | "Invalid inputs. Enter non zero values with respect to the sign convention." |
| 102 | ) |
| 103 | object_distance = 1 / ((1 / focal_length) - (1 / distance_of_image)) |
| 104 | return object_distance |
| 105 | |
| 106 | |
| 107 | def image_distance(focal_length: float, distance_of_object: float) -> float: |
nothing calls this directly
no outgoing calls
no test coverage detected