>>> from math import isclose >>> isclose(image_distance(10, 40), 13.33333333) True >>> from math import isclose >>> isclose(image_distance(1.5, 6.7), 1.932692308) True >>> image_distance(0, 0) # doctest: +NORMALIZE_WHITESPACE Traceback (most recent call last):
(focal_length: float, distance_of_object: float)
| 105 | |
| 106 | |
| 107 | def image_distance(focal_length: float, distance_of_object: float) -> float: |
| 108 | """ |
| 109 | >>> from math import isclose |
| 110 | >>> isclose(image_distance(10, 40), 13.33333333) |
| 111 | True |
| 112 | >>> from math import isclose |
| 113 | >>> isclose(image_distance(1.5, 6.7), 1.932692308) |
| 114 | True |
| 115 | >>> image_distance(0, 0) # doctest: +NORMALIZE_WHITESPACE |
| 116 | Traceback (most recent call last): |
| 117 | ... |
| 118 | ValueError: Invalid inputs. Enter non zero values with respect |
| 119 | to the sign convention. |
| 120 | """ |
| 121 | |
| 122 | if distance_of_object == 0 or focal_length == 0: |
| 123 | raise ValueError( |
| 124 | "Invalid inputs. Enter non zero values with respect to the sign convention." |
| 125 | ) |
| 126 | image_distance = 1 / ((1 / focal_length) - (1 / distance_of_object)) |
| 127 | return image_distance |
nothing calls this directly
no outgoing calls
no test coverage detected