Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1.  
  2. #!/usr/bin/env python -tt
  3. """ File: tempConv.py """
  4.  
  5.  
  6. # This method takes a celcius intiger and conferts it to farenhight
  7. def celToFer(celcius):
  8. """Summary line: Convert celcius to freinheight
  9. Description: Passed an int and return an int each representing the
  10. temprature in the respective units.
  11. """
  12.  
  13. freinheight = ((celcius*9.0)/5.0)+32.0
  14. return freinheight
  15.  
  16.  
  17. # This method takes a farengehight intiger and conferts it to celcius
  18. def ferToCel(freinheight):
  19. """Summary line: Convert freinheight to celcius
  20. Description: Passed an int and return an int each representing the
  21. temprature in the respective units.
  22. """
  23.  
  24. celcius = ((freinheight - 32.0)*5.0)/9.0
  25. return celcius
  26.  
  27.  
  28. # This method takes a kelvin input and converts it to cel
  29. def kelToCel(kelvin):
  30. """Summary line: Convert kelvin to celcius
  31. Description: Passed an int and return an int each representing the
  32. temprature in the respective units.
  33. """
  34.  
  35. celcius = kelvin - 273.15
  36. return celcius
  37.  
  38.  
  39. # This method takes a kelvin input and converts it to cel
  40. def celTokel(celcius):
  41. """Summary line: Convert celcius to kelvin
  42. Description: Passed an int and return an int each representing the
  43. temprature in the respective units.
  44. """
  45.  
  46. kelvin = celcius + 273.15
  47. return kelvin
  48.  
  49.  
  50.  
  51.  
  52. if __name__ == '__main__':
  53. """Summary line: Take input from user and return a converted value. Using
  54. either kelvin celcius or ferinneight.
  55. Description: Prompt user for input, split the srting value and remove null spaces.
  56. The input string values are decoded and then the int value is passed to the desired
  57. method.
  58. """
  59.  
  60.  
  61.  
  62. print "\nThis program converts degrees celcius and ferinhight."
  63. print """
  64. Enter the current units followed by the ones desifred then the current value
  65. For Example to convert 32 deg celcius to kelvin input 'C K 32'"""
  66.  
  67. lookUpTable = ['c', 'C', 'f', 'F', 'k', 'K']
  68.  
  69. toConvert = raw_input('>')
  70. toConvertSort = toConvert.split(' ')
  71. toConvertSort = [x for x in toConvertSort if x is not '']
  72.  
  73. while (toConvertSort[0] and toConvertSort[1] in lookUpTable):
  74. # c k c to f
  75. if toConvertSort[0] in lookUpTable[0:2]:
  76. if toConvertSort[1] in lookUpTable[4:6]:
  77. kelvin = celTokel(int(toConvertSort[2]))
  78. print "%.1f celcius is %.1f kelvin\n" % (int(toConvertSort[2]), kelvin)
  79.  
  80. elif toConvertSort[1] in lookUpTable[2:4]:
  81. freinheight = celToFer(int(toConvertSort[2]))
  82. print "%.1f celcius is %.1f freinheight\n" % (int(toConvertSort[2]), freinheight)
  83.  
  84. # k c # k f
  85. elif toConvertSort[0] in lookUpTable[4:6]:
  86. if toConvertSort[1] in lookUpTable[0:2]:
  87. celcius = kelToCel(int(toConvertSort[2]))
  88. print "%.1f kelvin is %.1f celcius\n" % (int(toConvertSort[2]), celcius)
  89.  
  90. elif toConvertSort[1] in lookUpTable[2:4]:
  91. celcius = kelToCel(int(toConvertSort[2]))
  92. freinheight = celToFer(int(celcius))
  93. print "%.1f kelvin is %.1f freinheight\n" % (int(toConvertSort[2]), freinheight)
  94.  
  95. # f c # f k
  96. elif toConvertSort[0] in lookUpTable[2:4]:
  97. if toConvertSort[1] in lookUpTable[0:2]:
  98. celcius = ferToCel(int(toConvertSort[2]))
  99. print "%.1f freinheight is %.1f celcius\n" % (int(toConvertSort[2]), celcius)
  100.  
  101. elif toConvertSort[1] in lookUpTable[4:6]:
  102. celcius = ferToCel(int(toConvertSort[2]))
  103. kelvin = celTokel(int(celcius))
  104. print "%.1f freinheight is %.1f kelvin\n" % (int(toConvertSort[2]), kelvin)
  105.  
  106.  
  107. toConvert = raw_input('>')
  108. toConvertSort = toConvert.split(' ')
  109. toConvertSort = [x for x in toConvertSort if x is not '']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement