Skip to content

Instantly share code, notes, and snippets.

@sunilw
Last active January 3, 2016 19:59
Show Gist options
  • Save sunilw/8512400 to your computer and use it in GitHub Desktop.
Save sunilw/8512400 to your computer and use it in GitHub Desktop.
Tip Calculator, version 4
#!/usr/bin/python
from __future__ import division
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--mealcost",
type=float,
required=True,
help="The cost of the meal without before tax or tip"
)
parser.add_argument(
"--tax",
type=float,
required=True,
default=10,
help="The percentage of tax. Do not include percent sign"
)
parser.add_argument(
"--tip",
type=float,
required=True,
help="The percentage for the tip. Do not include percent sign"
)
args = parser.parse_args()
mealcost = args.mealcost
tax = args.tax
tip = args.tip
# return the amount of tax that is payable on the meal
def tax_payable():
return mealcost * ( tax / 100)
#return the due tip amount
def tip_payable():
return mealcost * (tip / 100)
def meal_total():
tip = tip_payable()
tax = tax_payable()
return mealcost + tip + tax
def meal_plus_tax():
return mealcost + tax_payable()
def meal_plus_tip():
return mealcost + tip_payable()
def tc_format(n):
return "$%.2f" % n
#output our results
def printall():
print "The cost of meal plus tax is:" + tc_format(meal_plus_tax())
print "The cost of meal plus tip is: " + tc_format(meal_plus_tip())
print "The all-inclusive cost: " + tc_format(meal_total())
printall()
@sunilw
Copy link
Author

sunilw commented Jan 19, 2014

Thinkful homework for python course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment