Last active
September 16, 2018 17:31
-
-
Save enile8/3167350 to your computer and use it in GitHub Desktop.
Python temp conversion
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
#################################################################### | |
#Python program to convert temperature from either Fahrenheit to # | |
#Celsius or vise-versa. This is a very simple function example. # | |
# # | |
#################################################################### | |
def convert(temp, unit): | |
unit = unit.lower() | |
if unit == "c": | |
temp = 9.0 / 5.0 * temp + 32 | |
return "%s degrees Fahrenheit"% temp | |
if unit == "f": | |
temp = (temp - 32) / 9.0 * 5.0 | |
return "%s degrees Celsius"% temp | |
intemp = int(raw_input("What is the temperature?\n")) | |
inunit = str(raw_input("Please enter the unit of measure (f or c):\n")) | |
print convert(intemp, inunit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been trying to figure this out for months
many thanks