Skip to content

Instantly share code, notes, and snippets.

@toastdriven
Created March 11, 2010 04:43
Show Gist options
  • Select an option

  • Save toastdriven/328832 to your computer and use it in GitHub Desktop.

Select an option

Save toastdriven/328832 to your computer and use it in GitHub Desktop.
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