April 24, 2026

Functions in Python (Definition, Arguments & Return Values)

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
๐Ÿ’ก Key Insight: Functions help in modular programming and reduce repetition.

๐Ÿ”ท 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

  1. Which keyword is used to define a function?
    a) func
    b) def
    c) function
    d) define
    Answer: b

  2. Arguments are:
    a) Output values
    b) Input values
    c) Variables only
    d) Operators
    Answer: b

  3. 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:

Question Bank Unit 2: Control Structures & Functions

For more details: Basics of Python Programming for Pharmaceutical Sciences