Skip to content

Instantly share code, notes, and snippets.

@enile8
Last active September 16, 2018 17:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save enile8/3167350 to your computer and use it in GitHub Desktop.
Save enile8/3167350 to your computer and use it in GitHub Desktop.
Python temp conversion
####################################################################
#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)
Copy link

ghost commented Dec 23, 2017

I've been trying to figure this out for months

many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment