Created
March 11, 2010 04:43
-
-
Save toastdriven/328832 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| from decimal import Decimal | |
| import sys | |
| if len(sys.argv) != 2: | |
| print('Usage: expenser.py <filename>') | |
| sys.exit() | |
| exp = open(sys.argv[1], 'r') | |
| amounts = [] | |
| count = 0 | |
| for line in exp: | |
| line = line.strip() | |
| if line: | |
| try: | |
| amounts.append(Decimal(line)) | |
| count += 1 | |
| except: | |
| print("Couldn't parse '%s'. Moving on..." % line) | |
| total = sum(amounts) | |
| print("Total: $%s" % total) | |
| print("Mean: $%.02f" % (total / count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment