Created
December 8, 2012 22:25
-
-
Save Softwave/4242251 to your computer and use it in GitHub Desktop.
Temperature converter
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
#!/usr/bin/python | |
# Simple Temperature Converter Written in Python | |
# License: Public Domain | |
# Usage: conv input_unit value | |
# Usage example: tempconv F 32 | |
import sys | |
#Welcome | |
tcversion = 1.0 | |
print 'TempConv v. {} '.format(tcversion) | |
print 'Simple temperature converter tool' | |
print '\r\r' | |
# Functions | |
def fconv(finput): | |
coutput = (((finput - 32) * 5) / 9) | |
koutput = coutput + 273.15 | |
routput = finput + 459.67 | |
print '{} degrees Fahrenheit converts to: '.format(finput) | |
print '\r' | |
print 'Celsius: {}'.format(coutput) | |
print 'Kelvin: {}'.format(koutput) | |
print 'Rankine: {}'.format(routput) | |
def cconv(cinput): | |
foutput = (((cinput * 9) / 5) + 32) | |
koutput = cinput + 273.15 | |
routput = foutput + 459.67 | |
print '{} degrees Celsius converts to: '.format(cinput) | |
print '\r' | |
print 'Fahrenheit: {}'.format(foutput) | |
print 'Kelvin: {}'.format(koutput) | |
print 'Rankine: {}'.format(routput) | |
def kconv(kinput): | |
coutput = kinput - 273.15 | |
foutput = (((coutput * 9) / 5) + 32) | |
koutput = coutput + 273.15 | |
routput = foutput + 459.67 | |
print '{} degrees Kelvin converts to: '.format(kinput) | |
print '\r' | |
print 'Fahrenheit: {}'.format(foutput) | |
print 'Celsius: {}'.format(coutput) | |
print 'Rankine: {}'.format(routput) | |
def rconv(rinput): | |
foutput = rinput - 459.67 | |
coutput = (((foutput - 32) * 5) / 9) | |
koutput = coutput + 273.15 | |
print '{} degrees Rankine converts to: '.format(rinput) | |
print '\r' | |
print 'Fahrenheit: {}'.format(foutput) | |
print 'Celsius: {}'.format(coutput) | |
print 'Kelvin: {}'.format(koutput) | |
# Main | |
if len(sys.argv) != 3: | |
sys.exit("You must enter input in the correct format.") | |
if sys.argv[1] in ['F', 'f', 'Fahrenheit', 'fahrenheit']: | |
#Convert from Fahrenheit | |
fval = float(sys.argv[2]) | |
fconv(fval) | |
if sys.argv[1] in ['C', 'c', 'Celsius', 'celsius']: | |
#Convert from Celsius | |
cval = float(sys.argv[2]) | |
cconv(cval) | |
if sys.argv[1] in ['K', 'k', 'Kelvin', 'kelvin']: | |
#Convert from Kelvin | |
kval = float(sys.argv[2]) | |
kconv(kval) | |
if sys.argv[1] in ['R', 'r', 'Rankine', 'rankine']: | |
#Convert from Rankine | |
rval = float(sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment