My Father’s Old Calculator Taught Me Everything About Python Modules

Kumkum HiraniKumkum Hirani
5 min read

One rainy afternoon, I visited my father’s general store. The air smelled of wet soil and freshly opened cardboard boxes. A small crowd had gathered at the shop some customers waiting with their daily essentials, others chatting idly, while a few stood impatiently near the billing counter. My father was trying to manage the rush, calculating totals, applying discounts, and adding GST all with his trusted, slightly worn-out calculator.

I stepped in to help him at the counter. As I began punching in numbers, price, quantity, discount percentage, tax rate, I found myself repeating the same steps over and over for each customer. First, the total was calculated based on the quantity and price. Then a discount was applied. Finally, the tax was added. Different values, yes, but the process remained exactly the same every single time.

Somewhere between the third and fourth customer, it struck me.
This repetitive, rule-based routine mirrored something I had just recently learned while studying Python: the concept of modules.

Just like how billing was broken down into smaller, consistent steps, calculating total, applying discount, adding tax, Python modules allow you to break your code into reusable, manageable pieces. And right there, in the middle of that busy shop, I finally understood why modules weren’t just a programming best practice, they were a reflection of how real-life systems work efficiently.

What Are Python Modules?

Imagine you have a giant toolbox at your father’s shop. Instead of dumping all tools in one big box, you arrange them into labeled drawers: one for cutting tools, one for measuring tools, another for electrical tools.

Similarly in Python, a module is just a file that contains functions, variables, or classes you want to reuse. Instead of stuffing everything into a single script, you create separate .py files (modules) and import them when needed.

This improves readability, reusability, and organization, just like labeled drawers in that toolbox.

Step 1: Creating a Python Module

Let’s create a file called billing_utils.py for basic calculations.

# billing_utils.py

def calculate_total(price, quantity):
    return price * quantity

def apply_discount(total, discount_percent):
    return total - (total * discount_percent / 100)

def add_gst(amount, gst_percent=18):
    return amount + (amount * gst_percent / 100)

This file has three functions:

  • calculate_total: Multiplies price and quantity.

  • apply_discount: Applies a discount percentage.

  • add_gst: Adds GST (default 18%).

Now, this module is ready for use—just like a labeled drawer of pricing tools.

Step 2: Importing a Module

Let’s say we have another file called main.py where we want to use the functions from billing_utils.py.

# main.py

import billing_utils

price = 100
quantity = 3

total = billing_utils.calculate_total(price, quantity)
total_after_discount = billing_utils.apply_discount(total, 10)
final_amount = billing_utils.add_gst(total_after_discount)

print("Total:", total)
print("After Discount:", total_after_discount)
print("Final Amount with GST:", final_amount)

Output:

Total: 300
After Discount: 270.0
Final Amount with GST: 318.6

Just like picking the right tool from a labeled drawer, we used billing_utils.function_name() to access each function.

Step 3: Renaming a Module While Importing

Sometimes, module names can be long or you want a shorter alias to make your code cleaner.

Here’s how you can rename a module during import:

# main.py

import billing_utils as bu

total = bu.calculate_total(150, 2)
total_after_discount = bu.apply_discount(total, 5)
final_amount = bu.add_gst(total_after_discount)

print("Final Amount with GST:", final_amount)

Output:

Final Amount with GST: 285.6

Using as bu lets us use a shortcut. Instead of typing billing_utils, we use bu.

Step 4: Importing Specific Functions Only

What if you only need one function? Python lets you import only what you need:

# main.py

from billing_utils import add_gst

print(add_gst(100))

Output:

118.0

Cleaner and more memory-efficient!

Step 5: The Big Picture – A Modular System for My Father’s Shop

After a few days, I had several modules:

  • billing_utils.py: For billing calculations.

  • inventory_utils.py: For stock updates.

  • report_utils.py: For generating reports.

Each module was its own file, with focused responsibilities.

# inventory_utils.py

def update_stock(item, quantity_sold, stock):
    stock[item] -= quantity_sold
    return stock
# report_utils.py

def generate_invoice(customer_name, amount):
    return f"Invoice for {customer_name}: Rs. {amount}"

I imported and renamed them in main.py like this:

import billing_utils as bu
import inventory_utils as inv
import report_utils as rep

stock = {'pen': 50, 'notebook': 30}
price = 20
qty = 2

total = bu.calculate_total(price, qty)
total = bu.apply_discount(total, 10)
final = bu.add_gst(total)

stock = inv.update_stock('pen', qty, stock)
invoice = rep.generate_invoice('Ramesh', final)

print(invoice)
print("Updated stock:", stock)

Output:

Invoice for Ramesh: Rs. 39.6
Updated stock: {'pen': 48, 'notebook': 30}

Why Are Modules Important?

Using modules makes your code:

  • Organized: Functions are grouped meaningfully.

  • Reusable: You can use the same functions in multiple projects.

  • Maintainable: Easier to debug or update just one module.

  • Scalable: As your project grows, your code doesn’t become unmanageable.

Just like my father’s shop wouldn’t function well if all tools were scattered, a Python project suffers if everything is cramped in one file.

Final Thoughts

That simple rainy-day idea turned into a fully functioning billing system, all thanks to the power of Python modules.

When you organize your code into modules:

  • You think clearly,

  • You debug faster,

  • You grow like a pro.

So next time you're building a project, think like a shopkeeper: label your tools, store them neatly, and pull out only what you need.

Start modular, stay smart.

0
Subscribe to my newsletter

Read articles from Kumkum Hirani directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kumkum Hirani
Kumkum Hirani