69.9k views
1 vote
Write a program that uses a custom function to return the cost of purchasing an item, possibly in multiple quantities. The item might be subject to 7% sales tax. The main function should prompt the user to enter the quantity, unit price, and taxable data. The main function should call the custom function with these three inputs as arguments and print the cost of the purchase in currency format.

User Kakaja
by
4.9k points

1 Answer

7 votes

Answer:

def cost(quantity, unit_price, taxable):

if taxable == "Yes":

total = (quantity * unit_price) + (quantity * unit_price * 0.07)

elif taxable == "No":

total = quantity * unit_price

return total

q = int(input("Enter the quantity: "))

p = float(input("Enter the unit price: "))

t = input("Is %7 tax applicable? (Yes/No): ")

print(str("$" + str(cost(q, p, t))))

Step-by-step explanation:

- Create a function called cost that takes three parameters, quantity, unit price, and taxable

- If the tax is applicable, calculate the total with tax. Otherwise, do not add the tax.

- Return the total

- Ask the user for the inputs

- Call the function with given inputs and print the result

User Chuck Heatherly
by
6.9k points