python.py 478 B

12345678910111213141516171819
  1. #!/usr/local/bin/python
  2. import string, sys
  3. # If no arguments were given, print a helpful message
  4. if len(sys.argv)==1:
  5. print '''Usage:
  6. celsius temp1 temp2 ...'''
  7. sys.exit(0)
  8. # Loop over the arguments
  9. for i in sys.argv[1:]:
  10. try:
  11. fahrenheit=float(string.atoi(i))
  12. except string.atoi_error:
  13. print repr(i), "not a numeric value"
  14. else:
  15. celsius=(fahrenheit-32)*5.0/9.0
  16. print '%i\260F = %i\260C' % (int(fahrenheit), int(celsius+.5))