Mar-25-2017, 08:47 AM
Hey guys this is my first attempt at this program and I am having trouble with the second task which requires me to write a function that returns the amount of tax – it should include two parameters, one for the tax rate and another for the amount.
Also, using a for loop, call the function to calculate the tax on the user specified amount for tax rates of 5%, 10%, 15%, 20% and 25%:
So far I have managed to figure out how to write a basic code that takes the price of an item them returns the tax by a specific amount but I am struggling on how to return it in a list similar to this
5% tax on a Chocolate cake costing $17.50 is $0.88
10% tax on a Chocolate cake costing $17.50 is $1.75
15% tax on a Chocolate cake costing $17.50 is $2.62
20% tax on a Chocolate cake costing $17.50 is $3.50
25% tax on a Chocolate cake costing $17.50 is $4.38
Here is my code and output for the first part of my program
Any help is really appreciated :)
My code
Also, using a for loop, call the function to calculate the tax on the user specified amount for tax rates of 5%, 10%, 15%, 20% and 25%:
So far I have managed to figure out how to write a basic code that takes the price of an item them returns the tax by a specific amount but I am struggling on how to return it in a list similar to this
5% tax on a Chocolate cake costing $17.50 is $0.88
10% tax on a Chocolate cake costing $17.50 is $1.75
15% tax on a Chocolate cake costing $17.50 is $2.62
20% tax on a Chocolate cake costing $17.50 is $3.50
25% tax on a Chocolate cake costing $17.50 is $4.38
Here is my code and output for the first part of my program
Any help is really appreciated :)
My code
print ("This is a tax calculator. Enter in the price and your item\n" "and the program will calculate how much it costs with tax.""") #Create tax function that takes price and tax_rate as imputs and returns the total price def calculate_tax(price, tax_rate): total = price + (price * tax_rate) total = round(total, 2) return total #float is a variable type for decimals item = str(input("Please enter an item")) my_price = float(input("Price of the item $")) tax = calculate_tax(my_price,.0875) print ("The price of",item,"with tax: $",tax,"")Aaaand my output is something like this:
This is a tax calculator. Enter in the price and your item and the program will calculate how much it costs with tax. Please enter an itemChocolate Cake Price of the item $17.50 The price of Chocolate Cake with tax:$ 19.03 Process finished with exit code 0