Skip to content

Instantly share code, notes, and snippets.

@kottenator
Created November 11, 2016 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kottenator/7e748b61fd8fb7c79a993b2e97db5970 to your computer and use it in GitHub Desktop.
Save kottenator/7e748b61fd8fb7c79a993b2e97db5970 to your computer and use it in GitHub Desktop.
Simple temperature calculator (°C / °F)
c = lambda f: (f - 32) * 5 / 9.; f = lambda c: c * 9 / 5. + 32; print('\n'.join(u'{2:>6} °C ← °F {0:>4} °C → °F {1:6}'.format(i * 10, f(i * 10), round(c(i * 10), 1)) for i in range(-10, 11)))
def c(f):
return (f - 32) * 5 / 9.
def f(c):
return c * 9 / 5. + 32
print('\n'.join(
u'{2:>6} °C ← °F {0:>4} °C → °F {1:6}'.format(
i * 10, f(i * 10), round(c(i * 10), 1)
) for i in range(-10, 11)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment