#!/usr/bin/python # # relchange.py # # Computes the relative change between two numbers. # # Copyright (c) 2006 Marco Colombo # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # See http://www.gnu.org/licenses/gpl.txt for a copy of the license. # import sys # # main # def main(argv = None): # change argv if we are not running from the interactive prompt if argv is None: argv = sys.argv # check if we have the correct number of arguments if len(argv) != 3: print "Usage: relchange.py " return 1 # take the file names from the command line try: first = float(argv[1]) second = float(argv[2]) except ValueError: print "The values must be numeric." return 2 # compute and print the relative change res = (second - first)/first * 100 print "%4.1f%%" % res if __name__ == "__main__": sys.exit(main())