#!/usr/bin/python ## a program for doing temperature conversion. import sys ## convert Fahrenheit to Celsius def FtoC(F) : return (F - 32) * (5.0/9) ## convert Celsius to Fahrenheit def CtoF(C) : return (9/5.0) * C + 32 if __name__ == "__main__" : if len(sys.argv) < 3 : print "Usage: converter.py {-f | -c} temp" sys.exit(0) else : ### note the % operator being used to provide printf-style formatting if (sys.argv[1] == '-f') : print '%d degrees Fahrenheit is %d degrees Celsius' % \ (int(sys.argv[2]), FtoC(int(sys.argv[2]))) else : print '%d degrees Celsius is %d degrees Fahrenheit' % \ (int(sys.argv[2]), CtoF(int(sys.argv[2])))