156k views
3 votes
(Python) A taxable item named Widgets is available in multiple quantities at a base price of $24.99. In your program,

* Store the base price in a properly named constant as a decimal.
* Prompt the user for the number (integer amount) of Widgets being purchased.
* The sales tax rate is 7%. Store the tax rate in a properly named constant as a decimal.
* The shipping & handling cost is 1 dollar per Widget. Store the shipping and handling cost in a properly named constant.
* Calculate and print a receipt that includes
_the subtotal, the quantity, and the base cost on one line;
_the shipping and handling amount on the next line;
_the sales tax on the next line;
_and the total amount due on the last line after skipping a line.
* Ensure that your program's output is formatted as identified in the example output below, which includes a title prior to the data being printed.
* Display commas for numbers of 1,000 or more.
* Use dollar signs for dollar amounts and allow for two decimal places for cents.
* Note the apostrophe in Widgets' in the Example Output below. Your program should include that, too.
* As a reminder use f_string for all printing.

(Python) A taxable item named Widgets is available in multiple quantities at a base-example-1

1 Answer

1 vote

Here's my code:

# Constants

BASE_PRICE = 24.99

SALES_TAX_RATE = 0.07

SHIPPING_HANDLING_COST = 1.0

# Input

quantity = int(input("Enter the number of Widgets being purchased: "))

# Calculations

subtotal = BASE_PRICE * quantity

shipping_handling = SHIPPING_HANDLING_COST * quantity

sales_tax = subtotal * SALES_TAX_RATE

total = subtotal + shipping_handling + sales_tax

# Output

print("Receipt for Widgets' Purchase")

print(f"Quantity: {quantity}, Base Cost: ${BASE_PRICE:.2f}, Subtotal: ${subtotal:,.2f}")

print(f"Shipping & Handling: ${shipping_handling:.2f}")

print(f"Sales Tax: ${sales_tax:.2f}")

print(f"Total: ${total:.2f}")

User Fowl
by
8.2k points