Skip to content

Instantly share code, notes, and snippets.

@jonbalbarin
Created July 7, 2011 16:22
Show Gist options
  • Save jonbalbarin/1069890 to your computer and use it in GitHub Desktop.
Save jonbalbarin/1069890 to your computer and use it in GitHub Desktop.
a tip calculator in python
alias tippy='python ~/path/to/this/thing/tip.py -s'
import sys,getopt,time
def main():
try:
opts ,args = getopt.getopt(sys.argv[1:], "s:", ["subtotal="])
except getopt.GetoptError, err:
print str(err)
print "bad usage"
exit(1)
subtotal=0;
for o,a in opts:
if o in ("-s", "--subtotal"):
subtotal = float(a)
else:
assert False, "unrecognized option"
print "subtotal %f" % subtotal
withTax = subtotal*1.08875
print "with tax %f" % withTax
print "with tax and 10%% tip %f" % (withTax + (subtotal*0.1))
print "with tax and 15%% tip %f" % (withTax + (subtotal*0.15))
print "with tax and 20%% tip %f" % (withTax + (subtotal*0.2))
print "with tax and five dollars %f" % (withTax + 5)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment