Created
July 7, 2011 16:22
-
-
Save jonbalbarin/1069890 to your computer and use it in GitHub Desktop.
a tip calculator in python
This file contains 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
alias tippy='python ~/path/to/this/thing/tip.py -s' | |
This file contains 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
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