Doctests: >>> from math import isclose >>> isclose(object_distance(10,40), -13.333333333333332) True >>> from math import isclose >>> isclose(object_distance(6.2,1.5), 1.9787234042553192) True >>> object_distance(0, 20) # doctest: +NORMALIZE_WHITESPACE Traceba
(
focal_length_of_lens: float, image_distance_from_lens: float
)
| 77 | |
| 78 | |
| 79 | def object_distance( |
| 80 | focal_length_of_lens: float, image_distance_from_lens: float |
| 81 | ) -> float: |
| 82 | """ |
| 83 | Doctests: |
| 84 | >>> from math import isclose |
| 85 | >>> isclose(object_distance(10,40), -13.333333333333332) |
| 86 | True |
| 87 | |
| 88 | >>> from math import isclose |
| 89 | >>> isclose(object_distance(6.2,1.5), 1.9787234042553192) |
| 90 | True |
| 91 | |
| 92 | >>> object_distance(0, 20) # 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 image_distance_from_lens == 0 or focal_length_of_lens == 0: |
| 100 | raise ValueError( |
| 101 | "Invalid inputs. Enter non zero values with respect to the sign convention." |
| 102 | ) |
| 103 | |
| 104 | object_distance = 1 / ((1 / image_distance_from_lens) - (1 / focal_length_of_lens)) |
| 105 | return object_distance |
| 106 | |
| 107 | |
| 108 | def image_distance( |
nothing calls this directly
no outgoing calls
no test coverage detected