Last active
January 3, 2016 13:29
-
-
Save sunilw/8469898 to your computer and use it in GitHub Desktop.
Thinkful homework. Tax Calculator, version 3
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
#!/usr/bin/python | |
from __future__ import division | |
import sys | |
welcome = """ | |
################################### | |
Meal Tip calculator | |
################################### | |
""" | |
help = """ | |
## how to use this tool | |
first input: the cost of your meal | |
second input: the tip percentage | |
third input: the tax rate percentage | |
""" | |
print welcome | |
if len(sys.argv) != 4: | |
print help | |
sys.exit("you gave the wrong number of args") | |
# print help | |
if sys.argv[1] == "help": | |
print help | |
# otherwise, get inputs | |
meal_base_cost = float(sys.argv[1]) | |
tip_percentage = float(sys.argv[2]) | |
tax_rate = float(sys.argv[3]) | |
# calculate meal cost with tax | |
def calculate_meal_with_tax(meal_base_cost, tax_rate): | |
tax = (tax_rate / 100) | |
base = meal_base_cost | |
total = base + ( base * tax) | |
return total | |
#calculate the dollar amout of the tip | |
def calculate_tip(meal_base_cost, tip_percentage): | |
meal_base_cost = meal_base_cost | |
tip_value = meal_base_cost *(tip_percentage / 100) | |
return tip_value | |
def calculate_tax_cost(meal_base_cost, tax_rate): | |
meal_base_cost = meal_base_cost | |
tax_cost = meal_base_cost * (tax_rate / 100) | |
return tax_cost | |
def calculate_meal_with_tip(meal_base_cost, tip_percentage): | |
tip = (tip_percentage / 100) | |
base = meal_base_cost | |
total = base + (base * tip) | |
return total | |
def calculate_grand_total(): | |
tax = calculate_tax_cost(meal_base_cost, tip_percentage) | |
tip_value = calculate_tip(meal_base_cost, tip_percentage) | |
total = meal_base_cost + tax + tip_value | |
return total | |
def print_all_totals(): | |
with_tax = str(calculate_meal_with_tax(meal_base_cost, tax_rate)) | |
with_tip = str(calculate_meal_with_tip(meal_base_cost, tip_percentage)) | |
tip_value = str(calculate_tip(meal_base_cost, tip_percentage)) | |
tax = str(calculate_tax_cost(meal_base_cost, tax_rate)) | |
total = str(calculate_grand_total()) | |
print "The tax on the meal costs: $" + tax | |
print "The tip value of the meal is $" + tip_value | |
print "The meal with tax costs alone: $" + with_tax | |
print "The meal with the tip costs alone $" + with_tip | |
print "The total comes to $" + total | |
print_all_totals() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment