Simple Billing System in Python for Class 11
Last updated on August 22nd, 2025 at 08:23 pm
Python Program to Calculate Shopping Bill with Tax (Simple & Advanced)
When we go shopping, the bill usually contains two parts – the actual price of items and the tax applied.
In this article, we will learn how to create a Python program that calculates:
- Bill amount (without tax)
- Tax amount (calculated separately)
- Final amount (with tax included)
We will write two versions of the program:
1. Simple Version (using loops + if-elif-else)
2. Advanced Version (using dictionary)
Version 1: Simple Python Program using if-elif-else
This version is written for beginners who know only loops, if, elif, else statements.
#Program: Bill with Different Tax Rate (Simple Version) print("Available Products:") print("1. Pen - 10 Rs (5% tax)") print("2. Notebook - 50 Rs (12% tax)") print("3. Pencil - 5 Rs (0% tax)") print("4. Eraser - 8 Rs (5% tax)") print("5. Bag - 700 Rs (18% tax)") print("6. Shoes - 1200 Rs (28% tax)") print("Enter 0 to finish shopping.\n") bill_amount = 0 total_tax = 0 print("\n===== BILL DETAILS =====") print("Product\tQty\tPrice\tTotal\tTax") while True: choice = int(input("Enter product number (0 to stop): ")) if choice == 0: break qty = int(input("Enter quantity: ")) if choice == 1: price, tax_rate, name = 10, 5, "Pen" elif choice == 2: price, tax_rate, name = 50, 12, "Notebook" elif choice == 3: price, tax_rate, name = 5, 0, "Pencil" elif choice == 4: price, tax_rate, name = 8, 5, "Eraser" elif choice == 5: price, tax_rate, name = 700, 18, "Bag" elif choice == 6: price, tax_rate, name = 1200, 28, "Shoes" else: print("Invalid choice") continue item_total = price * qty item_tax = (item_total * tax_rate) / 100 bill_amount += item_total total_tax += item_tax # Print each purchased item directly print(f"{name:8}\t{qty}\t{price}\t{item_total}\t{item_tax:.2f}") final_amount = bill_amount + total_tax print("-----------------------------") print("Bill Amount (Without Tax): Rs", bill_amount) print("Total Tax: Rs", round(total_tax, 2)) print("Final Amount (With Tax): Rs", round(final_amount, 2)) print("=============================")
Sample Output:
Available Products: 1. Pen - 10 Rs (5% tax) 2. Notebook - 50 Rs (12% tax) 3. Pencil - 5 Rs (0% tax) 4. Eraser - 8 Rs (5% tax) 5. Bag - 700 Rs (18% tax) 6. Shoes - 1200 Rs (28% tax) Enter 0 to finish shopping. ===== BILL DETAILS ===== Product Qty Price Total Tax Enter product number (0 to stop): 2 Enter quantity: 1 Notebook 1 50 50 6.00 Enter product number (0 to stop): 5 Enter quantity: 2 Bag 2 700 1400 252.00 Enter product number (0 to stop): 0 ----------------------------- Bill Amount (Without Tax): Rs 1450 Total Tax: Rs 258.0 Final Amount (With Tax): Rs 1708.0 =============================
Version 2: Advanced Python Program using Dictionary
In this version, we use a dictionary to store product price and tax rate together. This makes the program more flexible and easy to update.
# Program: Bill with Different Tax Rate (Advanced Version) # Dictionary with product : (price, tax_rate%) products = { "Pen": (10, 5), "Notebook": (50, 12), "Pencil": (5, 0), "Eraser": (8, 5), "Bag": (700, 18), "Shoes": (1200, 28) } cart = {} print("Available Products (Price, Tax Rate):") for item, (price, tax) in products.items(): print(f"{item} - Rs{price} (Tax {tax}%)") print("\nEnter 'done' when finished.\n") while True: product = input("Enter product name: ").capitalize() if product.lower() == "done": break elif product in products: qty = int(input(f"Enter quantity of {product}: ")) cart[product] = cart.get(product, 0) + qty else: print("Product not available. Please choose from the list.") bill_amount = 0 total_tax = 0 print("\n===== BILL SUMMARY =====") for item, qty in cart.items(): price, tax_rate = products[item] item_total = price * qty item_tax = (item_total * tax_rate) / 100 bill_amount += item_total total_tax += item_tax print(f"{item} (x{qty}) = Rs {item_total} | Tax @{tax_rate}% = Rs {item_tax:.2f}") final_amount = bill_amount + total_tax print("-------------------------") print(f"Bill Amount (Without Tax): Rs {bill_amount}") print(f"Total Tax: Rs {total_tax:.2f}") print(f"Final Amount (With Tax): Rs {final_amount:.2f}") print("=========================")
Sample Output:
Available Products (Price, Tax Rate): Pen - Rs10 (Tax 5%) Notebook - Rs50 (Tax 12%) Pencil - Rs5 (Tax 0%) Eraser - Rs8 (Tax 5%) Bag - Rs700 (Tax 18%) Shoes - Rs1200 (Tax 28%) Enter 'done' when finished. Enter product name: pen Product not available. Please choose from the list. Enter product name: Pen Enter quantity of Pen: 2 Enter product name: Notebook Enter quantity of Notebook: 3 Enter product name: Product not available. Please choose from the list. Enter product name: Bag Enter quantity of Bag: 3 Enter product name: done ===== BILL SUMMARY ===== Pen (x2) = Rs 20 | Tax @5% = Rs 1.00 Notebook (x3) = Rs 150 | Tax @12% = Rs 18.00 Bag (x3) = Rs 2100 | Tax @18% = Rs 378.00 ------------------------- Bill Amount (Without Tax): Rs 2270 Total Tax: Rs 397.00 Final Amount (With Tax): Rs 2667.00 =========================
This version is suitable for Class 12 and project work, as it uses dictionary and is more professional. If you are just starting with Python and learning loops, if-elif-else, then go with Version 1 (Simple). If you are comfortable with dictionaries and lists, then try Version 2 (Advanced).Both programs clearly show bill amount, tax amount, and final amount separately.
Simple Billing System in Python
Here a simple billing software written in Python. It allows you to create invoices for customers, calculate discounts based on the payment method, and include additional costs for a carry bag. Here’s an explanation of the program for class 11 students:
- The program starts with an infinite loop using while True:. This loop continues running until the user decides to exit by pressing ‘0’.
- It greets the user and displays a menu of payment methods: Cash, UPI, and Card.
- It prompts the user to enter the name and address of the customer.
- The user is asked to select the payment method by entering a number (1 for Cash, 2 for UPI, 3 for Card).
- The program then asks for the number of items the customer has purchased.
- It creates an empty list called items to store item names and prices and initializes a total_price variable to keep track of the total cost.
- Inside a for loop, the program asks the user for the name and price of each item and adds them to the items It also updates the total_price with the cost of each item.
- Depending on the chosen payment method, the program calculates a discount: 5% for Cash, 10% for UPI, and 7% for Card.
- The program asks if the customer wants a carry bag and, if so, charges an additional Rs. 10 for it.
- It calculates the GST (Goods and Services Tax) at a rate of 18% on the total price after the discount.
- It calculates the final total price with GST, including the discount and carry bag cost.
- The program then displays an invoice with the customer’s name, address, payment method, discount, list of items and their prices, total price without GST, GST, carry bag cost, and the total price with GST.
- After displaying the invoice, it asks the user if they want to enter another entry or exit the program. If the user enters ‘0’, the loop will exit, and the program will terminate.
This program helps store owners or cashiers to quickly generate invoices for customers and calculate the total cost based on the payment method, while also offering discounts for certain payment methods and charging for optional items like a carry bag. It’s a basic example of a billing system and can be expanded or improved for real-world applications.
Source Code:
while True: print("Welcome to billing software!") print("Payment methods") print("1: Cash") print("2: UPI") print("3: Card") name = input('Enter the name of the customer: ') address = input('Enter the address of the customer: ') payment = int(input('Enter the mode of payment (1 for Cash, 2 for UPI, 3 for Card): ')) num_items = int(input("Enter how many items the customer has taken: ")) items = [] # List to store item names and prices total_price = 0 for i in range(num_items): item_name = input("Enter the name of the item: ") item_price = float(input("Price of the item: ")) items.append((item_name, item_price)) # Store item name and price in a tuple total_price += item_price discount = 0 # Initialize discount with a default value if payment == 1: # Cash discount = 0.05*total_price #for 5% discount elif payment == 2: # UPI discount = 0.10* total_price #for 10% discount elif payment == 3: # Card discount = 0.07* total_price #for 7% discount carry_bag = input("Does the customer want a carry bag? (Type 'y' for yes, 'n' for no): ") carry_bag_cost = 0 if carry_bag == "y": carry_bag_cost = 10 GST = 0.18*(total_price-discount) total_price_with_GST = ((total_price - discount) + GST + carry_bag_cost) print("---------------------------------------------------------------Invoice-------------------------------------------------------------------") print("Name of the customer is:", name) print("Address of the customer is:", address) if payment == 1: print("Mode of payment: Cash") print("You got a 5% discount") elif payment == 2: print("Mode of payment: UPI") print("You got a 10% discount") elif payment == 3: print("Mode of payment: Card") print("You got a 7% discount") print("Discount is Rs.", discount) print("Items purchased:") for item in items: print("Item:", item[0]) print("Price:", item[1]) print("Total without GST is Rs.", total_price - discount) print("GST is Rs.", GST) print("Carry Bag cost is Rs.", carry_bag_cost) print("Total price with GST is Rs.", total_price_with_GST) user_input = input("Press Enter key to enter another entry or '0' to exit: ") if user_input == "0": break
Output:
Welcome to billing software! Payment methods 1: Cash 2: UPI 3: Card Enter the name of the customer: "Harshit" Enter the address of the customer: "Ashok Nagar, Delhi" Enter the mode of payment (1 for Cash, 2 for UPI, 3 for Card): 2 Enter how many items the customer has taken: 5 Enter the name of the item: "Pen" Price of the item: 10 Enter the name of the item: "Book" Price of the item: 420 Enter the name of the item: "Marker" Price of the item: 35 Enter the name of the item: "Chart Papers" Price of the item: 50 Enter the name of the item: "Stapler" Price of the item: 55 Does the customer want a carry bag? (Type 'y' for yes, 'n' for no): "y" ------------------------Invoice------------------------------------------ ('Name of the customer is:', 'Harshit') ('Address of the customer is:', 'Ashok Nagar, Delhi') Mode of payment: UPI You got a 10% discount ('Discount is Rs.', 57.0) Items purchased: ('Item:', 'Pen') ('Price:', 10.0) ('Item:', 'Book') ('Price:', 420.0) ('Item:', 'Marker') ('Price:', 35.0) ('Item:', 'Chart Papers') ('Price:', 50.0) ('Item:', 'Stapler') ('Price:', 55.0) ('Total without GST is Rs.', 513.0) ('GST is Rs.', 92.34) ('Carry Bag cost is Rs.', 10) ('Total price with GST is Rs.', 615.34) Press Enter key to enter another entry or '0' to exit: