Celcius.py

From GM-RKB
Jump to navigation Jump to search

celcius.py is a Python program that converts temperature from Fahrenheit to Celcius.



References

#!/usr/bin/python

# from http://www.amk.ca/python/simple/celsius.html

import string, sys

# If no arguments were given, print a helpful message
if len(sys.argv)==1:
    print 'Usage: celsius temp1 temp2 ...'
    sys.exit(0)

# Loop over the arguments
for i in sys.argv[1:]:
    try: 
        fahrenheit=float(string.atoi(i))
    except string.atoi_error:
	print repr(i), "not a numeric value"
    else:
	celsius=(fahrenheit-32)*5.0/9.0
	print '%i\260F = %i\260C' % (int(fahrenheit), int(celsius+.5))