Created
May 6, 2015 19:31
-
-
Save halfnibble/18103af180be5c1deeeb to your computer and use it in GitHub Desktop.
Reusable functions
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
# Reusable temperature conversion function | |
def convert_temperature(to_scale, temperature): | |
if to_scale == "f" or to_scale == "F": | |
# Convert to Fahrenheit | |
return temperature * 9.0 / 5 + 32 | |
elif to_scale == "c" or to_scale == "C": | |
# Convert to Celsius | |
return (temperature - 32) * 5.0 / 9.0 | |
else: | |
print "Invalid to_scale argument." | |
# Examples | |
print convert_temperature("f", 0.0) | |
# prints 32.0 | |
print convert_temperature("c", 212.0) | |
# prints 100.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment