Unit II · Basics of Python Programming for Pharmaceutical Sciences (BP101T) · As per PCI B.Pharmacy Syllabus, NEP 2020
Once you understand functions, the natural next step is using them to build small, purpose-built programs. This article walks through two classic pharmaceutical examples — a drug dosage calculator and a BMI calculator — and shows how combining them demonstrates real modular programming.

What Is a Modular Program?
A modular program is a program divided into small, independent, reusable blocks called functions (modules). Instead of writing one long, tangled block of code, the task is split into parts — each function doing exactly one job.
Advantages of modular programming:
- Easier to understand — each function has one clear purpose
- Easier to debug — problems can be isolated to a single function
- Reusable — the same function can be called from anywhere in the program, or reused in a different program entirely
- Better maintenance — a formula change means updating one function, not searching the whole program
- Improved readability — well-named functions document what the program does
Why This Matters in Pharmaceutical Software
Accuracy is essential in any healthcare-related software. Modular programming keeps different calculations separate and independent, which reduces the chance that an error in one calculation silently affects another. In a real pharmaceutical application, tasks are typically split into their own modules: calculating drug dosage, calculating BMI, handling patient data, and generating reports.
Module 1: Drug Dosage Calculator
Theory: The dosage a patient should receive depends on their body weight and the prescribed dose per kilogram of body weight. Multiplying these gives the required dosage:
Dosage = Weight × Dose per kg
def calculate_dosage(weight, dose_per_kg):
return weight * dose_per_kg
# main program
w = float(input("Enter weight (kg): "))
d = float(input("Enter dose per kg: "))
result = calculate_dosage(w, d)
print("Required dosage:", result, "mg")
How it works: calculate_dosage() is a self-contained function that does one job — it takes weight and dose-per-kg as arguments, and returns the computed value rather than printing it directly, so the result can be reused elsewhere in a larger program.
Module 2: BMI Calculator
Theory: Body Mass Index (BMI) is obtained by dividing weight in kilograms by the square of height in metres:
BMI = Weight (kg) ÷ Height (m)²
def calculate_bmi(weight, height):
return weight / (height ** 2)
def bmi_category(bmi):
if bmi < 18.5:
return "Underweight"
elif bmi < 25:
return "Normal"
elif bmi < 30:
return "Overweight"
else:
return "Obese"
# main program
w = float(input("Enter weight (kg): "))
h = float(input("Enter height (m): "))
bmi = calculate_bmi(w, h)
category = bmi_category(bmi)
print("BMI:", bmi)
print("Category:", category)
How it works: this example uses two functions working together — calculate_bmi() only computes the numeric value, while bmi_category() separately interprets that number into a health category. Keeping calculation and interpretation in separate functions, rather than merging them, is what makes this genuine modular design.
Combining Both Modules into One Program
The dosage and BMI modules can be combined into a single complete program that collects both sets of inputs and reports both results in one run:
# Modular Program for Pharmaceutical Applications
# Includes: Dosage Calculation + BMI Calculation
def calculate_dosage(weight, dose_per_kg):
return weight * dose_per_kg
def calculate_bmi(weight, height):
return weight / (height ** 2)
def bmi_category(bmi):
if bmi < 18.5:
return "Underweight"
elif bmi < 25:
return "Normal"
elif bmi < 30:
return "Overweight"
else:
return "Obese"
# ---------------- Main Program ----------------
print("=== Pharmaceutical Modular Program ===")
print("\n--- Dosage Calculation ---")
weight_dose = float(input("Enter patient weight (kg): "))
dose_per_kg = float(input("Enter dose per kg (mg/kg): "))
dosage = calculate_dosage(weight_dose, dose_per_kg)
print("Required Dosage:", dosage, "mg")
print("\n--- BMI Calculation ---")
weight_bmi = float(input("Enter weight (kg): "))
height = float(input("Enter height (m): "))
bmi = calculate_bmi(weight_bmi, height)
category = bmi_category(bmi)
print("BMI:", round(bmi, 2))
print("Health Category:", category)
Sample run (weight 70 kg, dose 3 mg/kg, height 1.75 m):
=== Pharmaceutical Modular Program ===
--- Dosage Calculation ---
Required Dosage: 210.0 mg
--- BMI Calculation ---
BMI: 22.86
Health Category: Normal
Why Modular Design Scales
| Benefit | In this example |
|---|---|
| Accuracy | Each calculation lives in its own function, reducing the chance of human error in medical computations. |
| Reusability | calculate_dosage() can be reused for any drug without rewriting the logic. |
| Maintainability | If a formula changes, only that one function needs updating. |
| Scalability | New modules — e.g. blood pressure or blood sugar calculators — can be added without disturbing existing ones. |
Frequently Asked Questions
Why use return instead of print() inside these functions?
Returning a value lets the result be reused elsewhere in the program (for example, in a report or a further calculation), while printing directly inside the function would lock that function into only ever displaying output, not reusing it.
Can these formulas be used for real clinical dosing?
No. These are simplified teaching examples for learning modular programming logic. Real dosing decisions must always follow official pharmacology references, prescriber guidance, and clinical protocols — see our Disclaimer.
What is the difference between a function and a module in this context?
In this introductory context, "module" is used to mean a self-contained function performing one task. (In later Python topics, "module" also refers to a separate .py file of reusable code — the same underlying idea of separation and reuse, at a larger scale.)
Summary
Modular programming means splitting a program into small, focused functions rather than one long block of code. This example built two such modules — a dosage calculator and a BMI calculator with category interpretation — and combined them into a single program. The same pattern (input module, calculation module, processing module, output module) scales to much larger pharmaceutical software systems.
References
- Pharmacy Council of India (PCI). B.Pharm Regulations, NEP 2020 — BP101T Syllabus.
- Python Software Foundation. Python.org official documentation on functions.
- World Health Organization (WHO). BMI classification reference ranges.
