Functions in Python for Pharmacy Students (Dose Calculator, BMI & Modular Programming)
Functions in Python allow you to organize code into reusable blocks. In pharmaceutical applications, functions are essential for building dose calculators, BMI tools, and clinical decision systems.
๐ท What is a Function?
A function is a block of code that performs a specific task and can be reused multiple times.
def function_name():
statement
๐ท Calling a Function
def greet():
print("Hello Pharma World")
greet()
๐ท Function with Arguments
Arguments are inputs passed to a function.
def display_dose(dose):
print("Dose is:", dose)
display_dose(500)
๐ท Return Values
A function can return a value using return.
def add(a, b):
return a + b
result = add(5, 3)
print(result)
๐ Dose Calculator Function
def calculate_dose(weight, dose_per_kg):
return weight * dose_per_kg
dose = calculate_dose(60, 10)
print("Total Dose:", dose)
Reusable function for dose calculation.
๐ BMI Calculator Function
def calculate_bmi(weight, height):
return weight / (height ** 2)
bmi = calculate_bmi(70, 1.75)
print("BMI:", bmi)
๐ท Multiple Arguments Example
def patient_info(name, age):
print(f"{name} is {age} years old")
patient_info("John", 45)
๐ง Memory Trick
- def โ Define function
- Arguments โ Input
- return โ Output
- Function โ Reusable code
๐งช Practice Exercise
Create functions to:
- Calculate dose using weight
- Calculate BMI
- Display patient details
๐ MCQs
- Which keyword is used to define a function?
a) func
b) def
c) function
d) define
Answer: b - Arguments are:
a) Output values
b) Input values
c) Variables only
d) Operators
Answer: b - Which keyword returns a value?
a) print
b) input
c) return
d) break
Answer: c
โ FAQs
Why are functions important?
They reduce repetition and make code modular and reusable.
Where are functions used in pharmacy?
In dose calculators, BMI calculations, and clinical decision systems.
๐ฅ Download Function-Based Pharma Projects
Includes dose calculator and BMI calculator programs.
โก Next Topic: Modular Programming (Complete Pharma Applications) โ
Unit 2 Blog:
- Conditional Statements (if, if-else, if-elif)
- Nested Conditions (clinical decision logic)
- Loops (for, while) โ repetition in pharma data
- Break & Continue (control flow)
- Functions (definition, arguments, return values) (You are on this page)
- Modular Programming (Dose + BMI calculator)
Question Bank Unit 2: Control Structures & Functions
For more details: Basics of Python Programming for Pharmaceutical Sciences