Skip to content

Instantly share code, notes, and snippets.

@ChristianBagley
Forked from enile8/tempCon.py
Created September 18, 2017 22:11
Show Gist options
  • Save ChristianBagley/00e574322bdc5d5d91ebd199bcaf9498 to your computer and use it in GitHub Desktop.
Save ChristianBagley/00e574322bdc5d5d91ebd199bcaf9498 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment