livepython.net

11. Python Program to Print a Digital Receipt

MediumEscape sequences

Overview

In this challenge, you will use escape sequences in Python to format a digital receipt with proper alignment. This exercise will help you understand how to use \t (tab escape sequences) to create structured and readable output.

Task

Write a Python program that prints a purchase receipt in a neatly formatted manner using tab escape sequences. The receipt should include a list of purchased items, their quantities, prices, and the total cost.

Expected Output

Your program should print the following receipt exactly as shown:

Your Purchase Receipt
--------------------------
Item Quantity Price
Apple 2kg $5.00
Milk 1L $2.00
Banana 1 dozen $2.50
--------------------------
Total $9.50
Thank you for shopping with us!

Input

  • No input is required.

Output

  • A formatted receipt displaying item names, their quantities, prices, and the total amount.

Your Purchase Receipt
--------------------------
Item Quantity Price
Apple 2kg $5.00
Milk 1L $2.00
Banana 1 dozen $2.50
--------------------------
Total $9.50
Thank you for shopping with us!

This exercise will help you practice string formatting and improve your ability to create structured console outputs!

Learn this firstChapter 2 · Escape Sequences in Python: \n, \t and More
solution.py
# write your code here

EXPECTED OUTPUT

1Your Purchase Receipt
2--------------------------
3Item Quantity Price
4Apple 2kg $5.00
5Milk 1L $2.00
6Banana 1 dozen $2.50
7--------------------------
8Total $9.50
9Thank you for shopping with us!

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.