Created
May 30, 2016 23:23
-
-
Save Yomi0/d8e984a01568ca42bcac41b1433bc626 to your computer and use it in GitHub Desktop.
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
| # Design a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 4 percent and the county sales tax is 2 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale. (which is the sum of the amount of purchase plus the total sales tax). | |
| # Hint: Use the value 0.02 to represent 2 percent, and 0.04 to represent 4 percent. | |
| # Chapter 3 — Rewrite using functions instead... | |
| # Get input | |
| # Perfrom calculations... | |
| # Print results... | |
| """ | |
| define several functions: | |
| main() | |
| calculate_tax() | |
| display() | |
| So, here's what needs to happen: | |
| main is called (main also asks for input) | |
| from main() calculate_tax() and display() are called. | |
| calculate_tax() should reccive the information from the variable amt_of_purchase | |
| calculate_tax() then needs to pass that information to display() | |
| what if I made the tax a global variable and never modify it? | |
| display() gets information from calculate_tax()... | |
| """ | |
| def main(): | |
| amt_of_purchase = float(input("Please enter your total purchase amount: ")) | |
| calculate_tax(amt_of_purchase) | |
| def calculate_tax(purchase_with_tax): | |
| county_sales_tax = 0.02 * applied_county_tax # 0.02 is county tax | |
| state_sales_tax = 0.04 * applied_state_tax # 0.04 is state sales tax | |
| # total_tax = format(county_sales_tax + state_sales_tax, '.2f') | |
| def display(purchase, purchase_with_tax, state_tax, county_tax): | |
| print("subtotal (before tax): $", format(purchase, '.2f')) | |
| print("sales tax: $", format(state_tax, '.2f')) | |
| print("county tax: $", format(county_tax, '.2f')) | |
| print("Total Tax: $", total_tax) | |
| print("Grand Total: $", format((purchase + county_tax + state_tax), '.2f')) | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment