Last active
January 4, 2016 13:39
-
-
Save notblizzard/8629555 to your computer and use it in GitHub Desktop.
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
def fahrenheit_to_celsius(a): | |
new_temp = (a - 32) * 5/9 | |
new_temp = float(new_temp) | |
print "{0} Fahrenheit converted to Celsius is {1}.".format(a, new_temp) | |
def celsius_to_fahrenheit(a): | |
new_temp = a * 9/5 + 32 | |
new_temp = float(new_temp) | |
print "{0} Celsius converted to Fahrenheit is {1}.".format(a, new_temp) | |
def kelvin_to_fahrenheit(a): | |
new_temp = 1.8 *(a - 273) + 32 | |
new_temp = float(new_temp) | |
print "{0} Kelvin converted to Fahrenheit is {1}.".format(a, new_temp) | |
def kelvin_to_celsius(a): | |
new_temp = a - 273 | |
new_temp = float(new_temp) | |
print "{0} Kelvin converted to Celsius is {1}.".format(a, new_temp) | |
def fahrenheit_to_kelvin(a): | |
new_temp = (5/9 * (a - 32) + 273 | |
new_temp = float(new_temp) | |
print "{0} Fahrenheit converted to Kelvin is {1}".format(a, new_temp) | |
def celsius_to_kelvin(a): | |
new_temp = a + 273 | |
new_temp = float(new_temp) | |
print "{0} Celsius converted to Kelvin is {1}".format(a, new_temp) | |
number = True | |
print "Welcome to the Temperature Converter!" | |
typetemp = input("What are you converting to: Fahrenheit to Kelvin(F2K), Fahrenheit to Celsius(F2C), Celsius to Fahrenheit(C2F), Celsius to Kelvin(C2K), Kelvin to Fahrenheit(K2F), or Kelvin to Celsius(K2C)?") | |
if (typetemp == 'F2K'): | |
temp = input("Okay, Fahrenheit to Kelvin! Enter in the temp for Fahrenheit!") | |
while (number == True): | |
try: | |
temp = int(temp) | |
fahernheit_to_kelvin(temp) | |
number = False | |
except ValueError: | |
print "Sorry, what you entered in is not a number." | |
elif (typetemp == 'F2C'): | |
temp = input("Okay, Fahrenheit to Celsius! Enter in the temp for Fahrenheit!") | |
while (number == True): | |
try: | |
temp = int(temp) | |
fahrenheit_to_celsius(temp) | |
number = False | |
except ValueError: | |
print "Sorry, what you entered in is not a number." | |
elif (typetemp == 'K2F'): | |
temp = input("Okay, Kelvin to Fahrenheit! Enter in a temp for Kelvin!") | |
while (number == True): | |
try: | |
temp = int(temp) | |
kelvin_to_fahrenheit(temp) | |
number = False | |
except ValueError: | |
print "Sorry, what you entered in is not a number." | |
elif (typetemp == 'K2C'): | |
temp = input("Okay, Kelvin to Celsius! Enter in a temp for Kelvin!") | |
while (number == True): | |
try: | |
temp = int(temp) | |
kelvin_to_celsius(temp) | |
number = False | |
except ValueError: | |
print "Sorry, what you entered in is not a number." | |
elif (typetemp == 'C2K'): | |
temp = input("Okay, Celsius to Kelvin! Enter in a temp for Celsius!") | |
while (number == True): | |
try: | |
temp = int(temp) | |
celsius_to_kelvin(temp) | |
number = False | |
except ValueError: | |
print "Sorry, what you entered in is not a number." | |
elif (typetemp == 'C2F'): | |
temp = input("Okay, Celsius to Fahrenheit! Enter in a temp for Celsius!") | |
while (number == True): | |
try: | |
temp = int(temp) | |
celsius_to_fahrenheit(temp) | |
number = False | |
except ValueError: | |
print "Sorry, what you entered in is not a number." | |
else: | |
print "You need to enter in one of the temperatures." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment