Advertisement
Guest User

Temp Converter

a guest
Dec 7th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. import sys
  2. print sys.argv
  3.  
  4. scale = raw_input("Please enter the first letter of the scale of temperature [F, C, K]: ")
  5. temp = raw_input("Please enter temperature: ")
  6. temp = int(temp)
  7.  
  8.  
  9. """ This function should take in scale & temp and run if statement
  10. logic on them to report the conversion of the temp from one scale to another"""
  11.  
  12. def convert(scale, temp):
  13.     if scale == "F":
  14.         f2c = fahrenheit2celsius(temp)
  15.         print "The temperature in Celsius is: " + str(f2c)
  16.         f2k = fahrenheit2kelvin(temp)
  17.         print "The temperature in Kelvin is: " + str(f2k)
  18.     elif scale == "C":
  19.         c2f = celsius2fahrenheit(temp)
  20.         print "The temperature in Fahrenheit is: " + str(c2f)
  21.         c2k = celsius2kelvin(temp)
  22.         print "The temperature in Kelvin is: " + str(c2k)
  23.     elif scale == "K":
  24.         k2f = kelvin2fahrenheit(temp)
  25.         print "The temperature in Fahrenheit is: " + str(k2f)
  26.         k2c = kelvin2celsius(temp)
  27.         print "The temperature in Celsius is: " + str(k2c)
  28.     else:
  29.         exit()
  30.  
  31. # converts fahrenheit to celsius
  32. def fahrenheit2celsius(fahrenheit):
  33.     celsius = (5.0 / 9) * (fahrenheit - 32)
  34.     return celsius
  35. # converts fahrenheit to kelvin
  36. def fahrenheit2kelvin(fahrenheit):
  37.     kelvin = (fahrenheit - 32) * (5 / 9.0) + 273.15
  38.     return kelvin
  39. # converts celsius to farenheit
  40. def celsius2fahrenheit(celsius):
  41.     fahrenheit = (celsius  * (9 / 5.0) + 32)
  42.     return fahrenheit
  43. # converts celsius to kelvin
  44. def celsius2kelvin(celsius):
  45.     kelvin = (celsius + 273.15)
  46.     return kelvin
  47. # converts kelvin to fahrenheit
  48. def kelvin2fahrenheit(kelvin):
  49.     fahrenheit = ((kelvin - 273.15) * 1.8) + 32
  50.     return fahrenheit
  51. # converts kelvin to celsius
  52. def kelvin2celsius(kelvin):
  53.     celsius = (kelvin - 273.15)
  54.     return celsius
  55.  
  56. convert(scale,temp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement