Created
February 24, 2022 02:31
-
-
Save jepler/d1a2440469e2228ad50073a3a94c2917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pint import UnitRegistry | |
ureg = UnitRegistry() | |
def conv_round(base, conv): | |
return round(base.to(conv)) | |
def gain(base, conv): | |
val = conv_round(conv) | |
return (val/base).magnitude | |
units = ( | |
ureg['m/s'], | |
ureg['knots'], | |
ureg['fathoms/sec'], | |
ureg['furlongs/min'], | |
ureg['kph'], | |
ureg['furlongs/hour'], | |
ureg['mph'], | |
ureg['yards/sec']) | |
v = 17 * ureg('mph') | |
e = 45 * ureg('mph') | |
while v < e: | |
print(f"{str(v):48} {round(v.to('mph'), 3):36}") | |
v = max(conv_round(v, u) for u in units) | |
print(f"{str(v):48} {round(v.to('mph')):36}") | |
gain is never used, is it?
Nice!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Classy.