Task 2 - Creating and Calling Functions#
2.1 - Calculating Taxes#
Write a Python function called calc_tax()
that calculates and prints the tax on a purchased item.
The input of this function should be the name of the item (a string), and the pre-tax price of the item (a number).
Requirements:
Add a docstring to this function so users know how to use it.
Calculate the provincial tax (5%) federal tax (7%), and store them as separate variables.
Choose one:
A) Add at least two assert statements as tests for your code OR
B) Use try/except statements to test for inputs to the function.
Print the item amount, the provincial tax, the federal tax, and the total with all taxes included.
Round tax amounts, and the final price to the nearest cent and display with exactly two decimal points.
Sample Output#
>> calc_tax(‘candy’, 10) # Run the
calc_tax()
function on candy to get the following outputcandy
pre-tax price of: $10.00
provincial tax: $0.50
federal tax: $0.70
total price of: $11.20
# add your import statements here
# Your solution here