Write a Python script to print a receipt of purchased items.

Mon, 12 Feb 2024 18:00

Write a Python script to print a receipt of purchased items.

When you buy things from a store, you are typically offered a receipt detailing your purchases on a piece of thermal paper (although some of my former students are working to change that!). In this assignment, you will write some Python code to generate such a receipt from a list of items.

Details

You will submit a Python script (named exactly receipt.py) that will input a list of items from the user, ask about their prices and tax status, and print out a receipt that summarizes the items, subtotal, taxes and total. Specifically, your code must:

  1. Prompt the user to enter some purchased items

    1. Print out a prompt and let the user type an item name (e.g., Apples)

    2. If the user enters an empty string, stop prompting for new items

  2. For each item that the user entered, ask the user how much it cost

  3. Prompt the user for a list of taxable items

    1. Print out a prompt and let the user type an item name (e.g., Apples)

    2. If the user enters an empty string, stop prompting for new taxable items

  4. Calculate the subtotal of items, taxes (15% of taxable items) and total

  5. Print out the receipt in the following format:

    ============================== (that's 30 equals signs)
    Receipt
    ------------------------------ (that's 30 hyphens)
    Apples 6.99
    Batteries 12.99 T              (the "T" means taxable)
    Carrots 5.99
    ------------------------------
    Subtotal 25.97
    ------------------------------
    Taxes 1.95                     (rounded to the nearest cent!)
    Total 27.92
    ==============================

    I’ll give you a bonus point if you can make the spacing look like a real receipt:

    ==============================
    Receipt
    ------------------------------
    Apples                  6.99
    Batteries              12.99 T
    Carrots                 5.99
    ------------------------------
    Subtotal               25.97
    ------------------------------
    Taxes                   1.95
    Total                  27.92
    ==============================

Suggestions / reminders

I would suggest that you start by solving part of the problem: just prompt for item names and print out a "receipt" that includes no prices. Then, once you’ve mastered that part of the work, move on to tackle more and more of the assignment. Remember, there is partial credit for partial work, but even more importantly, solving a piece of the problem at a time helps you solve it with confidence.

Remember, assignments are individual work: you must complete the assignment yourself.

You may also find it helpful to remember that we can concatenate strings together (making bigger strings out of smaller strings) using the addition operator (+).