Editor

Print a Formatted Receipt

Beginner · Write the code · from Python Input and Output: print(), input(), and Formatting

From the lesson: Python Input and Output: print(), input(), and Formatting

Every program needs a way to talk to the outside world. A weather app shows temperatures. A game displays your score. A calculator prints answers. All of these use output.

Read the lesson

Create a formatted receipt with the following items and prices. Use f-string alignment to left-align item names (20 characters wide) and right-align prices (8 characters wide, 2 decimal places). Include a header, separator, and total.

Items:

  • Laptop: 999.99
  • Mouse: 29.50
  • Keyboard: 74.99
  • Expected output:

    ============================
          TECH STORE
    ============================
    Item                   Price
    ----------------------------
    Laptop                999.99
    Mouse                  29.50
    Keyboard               74.99
    ----------------------------
    Total                1104.48
    ============================
    # Create the receipt
    items = [
    ("Laptop", 999.99),
    ("Mouse", 29.50),
    ("Keyboard", 74.99),
    ]
    # Print the header
    # Print column labels
    # Print each item
    # Print the total

    More Input and Output exercises

    All Python exercises · 50 practice problems · Python Fundamentals quiz