Going Further Lesson 23 of 23
Python Final Project — Sari-Sari Store Point of Sale
Build a complete console point-of-sale program for a sari-sari store with a product list, cart, receipts, payment and change, input validation and a sales file.
Let's build something real: a point-of-sale (POS) program for a sari-sari store. It shows the products, takes orders, computes the total and change, prints a receipt and saves each sale to a file. It uses almost everything from this course.
What the program does
- Shows a numbered menu of products with prices and stock.
- Lets the cashier add items to a cart by number and quantity.
- Refuses invalid input and quantities larger than the stock.
- Computes the total, asks for payment and computes the change.
- Prints a receipt and appends the sale to
sales.txt.
The complete program
Type it into a file named pos.py (typing it yourself teaches more than copying), then run it.
"""Tindahan ni Aling Nena – a simple point-of-sale program."""
from datetime import datetime
# ---------- data ----------
products = [
{"name": "Pandesal (10 pcs)", "price": 25.00, "stock": 40},
{"name": "Kape 3-in-1", "price": 8.00, "stock": 200},
{"name": "Itlog", "price": 9.00, "stock": 90},
{"name": "Instant Noodles", "price": 15.00, "stock": 120},
{"name": "Softdrink 1.5L", "price": 75.00, "stock": 24},
]
# ---------- helpers ----------
def ask_int(prompt, low, high):
"""Keep asking until the user types a whole number from low to high."""
while True:
try:
value = int(input(prompt))
if low <= value <= high:
return value
print(f" Please enter a number from {low} to {high}.")
except ValueError:
print(" Numbers only, please.")
def show_menu():
print("\n" + " MENU ".center(40, "="))
for i, p in enumerate(products, start=1):
print(f"{i}. {p['name']:<20} ₱{p['price']:>6.2f} ({p['stock']} left)")
print("0. Checkout")
def cart_total(cart):
return sum(item["price"] * qty for item, qty in cart)
def print_receipt(cart, paid):
total = cart_total(cart)
print("\n" + " TINDAHAN NI ALING NENA ".center(40, "-"))
print(datetime.now().strftime("%B %d, %Y %I:%M %p"))
for item, qty in cart:
line = item["price"] * qty
print(f"{qty:>3} x {item['name']:<20} ₱{line:>8.2f}")
print("-" * 40)
print(f"{'TOTAL':<26} ₱{total:>8.2f}")
print(f"{'CASH':<26} ₱{paid:>8.2f}")
print(f"{'CHANGE':<26} ₱{paid - total:>8.2f}")
print("Salamat po! Balik kayo! 😊".center(40))
def save_sale(cart):
with open("sales.txt", "a", encoding="utf-8") as f:
stamp = datetime.now().strftime("%Y-%m-%d %H:%M")
items = ", ".join(f"{qty}x {item['name']}" for item, qty in cart)
f.write(f"{stamp} | {items} | {cart_total(cart):.2f}\n")
# ---------- main program ----------
def main():
cart = []
while True:
show_menu()
choice = ask_int("Choose a product: ", 0, len(products))
if choice == 0:
break
product = products[choice - 1]
if product["stock"] == 0:
print(" Sorry, out of stock.")
continue
qty = ask_int(f" How many? (max {product['stock']}): ", 1, product["stock"])
product["stock"] -= qty
cart.append((product, qty))
print(f" Added. Current total: ₱{cart_total(cart):.2f}")
if not cart:
print("No items. Goodbye!")
return
total = cart_total(cart)
print(f"\nTotal to pay: ₱{total:.2f}")
while True:
try:
paid = float(input("Cash received: ₱"))
if paid >= total:
break
print(f" Kulang pa ng ₱{total - paid:.2f}.")
except ValueError:
print(" Please enter an amount.")
print_receipt(cart, paid)
save_sale(cart)
if __name__ == "__main__":
main()
A sample run
Output
================= MENU =================
1. Pandesal (10 pcs) ₱ 25.00 (40 left)
2. Kape 3-in-1 ₱ 8.00 (200 left)
3. Itlog ₱ 9.00 (90 left)
4. Instant Noodles ₱ 15.00 (120 left)
5. Softdrink 1.5L ₱ 75.00 (24 left)
0. Checkout
Choose a product: 2
How many? (max 200): 4
Added. Current total: ₱32.00
================= MENU =================
...
Choose a product: 3
How many? (max 90): 6
Added. Current total: ₱86.00
Choose a product: 0
Total to pay: ₱86.00
Cash received: ₱50
Kulang pa ng ₱36.00.
Cash received: ₱100
-------- TINDAHAN NI ALING NENA --------
December 02, 2026 10:30 AM
4 x Kape 3-in-1 ₱ 32.00
6 x Itlog ₱ 54.00
----------------------------------------
TOTAL ₱ 86.00
CASH ₱ 100.00
CHANGE ₱ 14.00
Salamat po! Balik kayo! 😊What each part teaches
| Part | Concepts used |
|---|---|
products | List of dictionaries |
ask_int | Functions, while True, try/except, chained comparison |
show_menu | for with enumerate, f-string alignment |
cart | List of tuples, sum with a generator |
print_receipt | datetime, string formatting |
save_sale | Appending to a file, join |
main | Loops, break, continue, conditions |
Challenges
- Add a 20% senior citizen/PWD discount option before payment.
- Let the cashier remove an item from the cart.
- Save the updated stock to a file and load it when the program starts, so stock is remembered between runs.
- Make a "daily report" option that reads
sales.txtand prints the total sales for today. - Rewrite the products as a
Productclass with asell()method.
What's next?
Congratulations on finishing the Python course! 🎉 From here you could:
- Learn SQL to store data in real databases.
- Explore data analysis with the
pandasandmatplotlibpackages. - Try Java or C++ to see how other languages handle the same ideas.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04