Head office, Rana Pratap Bagh, Delhi011 2721 1512+91 97116 99511

Science project idea

Python bill generator for a kirana shop

A price dictionary and a loop build a neat bill with totals and a discount rule. It shows how everyday billing can be programmed with formatted output.

What it shows

A price dictionary and a loop build a neat bill with totals and a discount rule. It shows how everyday billing can be programmed with formatted output.

The science

A bill is a list of lines, each with a quantity and a price, added into a total. A dictionary gives the price when you know the item name. Formatted strings with widths, such as :10 and :8.2f, line up the columns. A rule like a 5 percent discount above Rs 500 is an if statement applied to the final total.

Materials

Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.

  • A computer, laptop or phone with a browser (free)
  • Python 3 with IDLE, or the free Thonny editor, or an online Python runner (all free)
  • A price list of 6 items per kg or per piece written in rupees (made-up prices)
  • A notebook and a pencil

Safety

This project uses safe, everyday materials. Still, read the rules below with a parent before you start.

Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.

All the safety rules

Step by step

8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.

  1. Create bill.py and write prices = {"rice": 60, "dal": 120, "sugar": 45, "atta": 40, "oil": 150, "tea": 400}.

  2. Create an empty list lines = [] and total = 0.

  3. Start while True: with item = input("Item (or done): ").lower() and add if item == "done": break.

  4. If the item is not in prices print "Not available" and use continue.

  5. Read qty = float(input("Quantity: ")), set amount = prices[item] * qty, add total += amount and lines.append((item, qty, amount)).

  6. After the loop print a heading and then for name, qty, amt in lines: print(f"{name:10} {qty:6} {amt:8.2f}").

  7. Add discount = total * 0.05 if total > 500 else 0, then print the subtotal, the discount and the final amount total - discount.

  8. Test with two small bills, one under and one over Rs 500, and check the arithmetic by hand.

What you should see

The program prints a tidy table of items, quantities and amounts, applies a 5 percent discount only when the total is above Rs 500 and prints the final amount.

Viva questions

A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.

1Why use a dictionary for prices?

To look up the price from the item name.

2What does :8.2f mean?

A number in a field 8 wide with 2 decimal places.

3What does continue do?

Skips to the next loop round.

4How is the discount calculated?

Five percent of the total is 0.05 times the total.

Free ebook: Viva Questions for Science Projects

Take it further

Save every bill to a text file with the date and read it back to find the day’s total sales.

Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.

Free ebooks for this project

WhatsApp us