Your question is Convert Units Between Measures. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Granular field data may report measurements such as acres, hectares, feet, and meters. Given known conversion relationships, implement a function that converts a value from one unit to another, even when no direct relationship is provided.
Model each unit as a graph node. A conversion A -> B with factor f means one unit of A equals f units of B. The reverse relationship has factor 1 / f. Return None when the source and target units are disconnected.
Implement convert_units(value, source, target, conversions).
value is a real number.source and target are non-empty unit-name strings.conversions is a list of three-element lists [unit_a, unit_b, factor], where factor is positive and means 1 unit_a = factor unit_b.value in target units. Return value unchanged when source == target. Return None if no path exists.def convert_units(value, source, target, conversions):