Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- print sys.argv
- scale = raw_input("Please enter the first letter of the scale of temperature [F, C, K]: ")
- temp = raw_input("Please enter temperature: ")
- temp = int(temp)
- """ This function should take in scale & temp and run if statement
- logic on them to report the conversion of the temp from one scale to another"""
- def convert(scale, temp):
- if scale == "F":
- f2c = fahrenheit2celsius(temp)
- print "The temperature in Celsius is: " + str(f2c)
- f2k = fahrenheit2kelvin(temp)
- print "The temperature in Kelvin is: " + str(f2k)
- elif scale == "C":
- c2f = celsius2fahrenheit(temp)
- print "The temperature in Fahrenheit is: " + str(c2f)
- c2k = celsius2kelvin(temp)
- print "The temperature in Kelvin is: " + str(c2k)
- elif scale == "K":
- k2f = kelvin2fahrenheit(temp)
- print "The temperature in Fahrenheit is: " + str(k2f)
- k2c = kelvin2celsius(temp)
- print "The temperature in Celsius is: " + str(k2c)
- else:
- exit()
- # converts fahrenheit to celsius
- def fahrenheit2celsius(fahrenheit):
- celsius = (5.0 / 9) * (fahrenheit - 32)
- return celsius
- # converts fahrenheit to kelvin
- def fahrenheit2kelvin(fahrenheit):
- kelvin = (fahrenheit - 32) * (5 / 9.0) + 273.15
- return kelvin
- # converts celsius to farenheit
- def celsius2fahrenheit(celsius):
- fahrenheit = (celsius * (9 / 5.0) + 32)
- return fahrenheit
- # converts celsius to kelvin
- def celsius2kelvin(celsius):
- kelvin = (celsius + 273.15)
- return kelvin
- # converts kelvin to fahrenheit
- def kelvin2fahrenheit(kelvin):
- fahrenheit = ((kelvin - 273.15) * 1.8) + 32
- return fahrenheit
- # converts kelvin to celsius
- def kelvin2celsius(kelvin):
- celsius = (kelvin - 273.15)
- return celsius
- convert(scale,temp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement