Nested Conditional Statements in Python for Pharmacy Students (Clinical Decision Trees & Dose Optimization)
Nested conditional statements allow one if condition inside another. In pharmaceutical sciences, they are essential for handling complex clinical decisions involving multiple patient parameters.
๐ท What are Nested Conditional Statements?
A nested condition means placing an if statement inside another if or else block.
if condition1:
if condition2:
statement
๐ท Basic Example
age = 65
kidney_issue = True
if age > 60:
if kidney_issue:
print("Reduce dose significantly")
๐ Clinical Decision Tree Example
age = 70
kidney_issue = True
liver_issue = False
if age > 60:
if kidney_issue:
print("Reduce dose by 50%")
elif liver_issue:
print("Monitor liver function")
else:
print("Slight dose reduction")
else:
print("Standard dose")
This structure mimics how clinicians evaluate multiple patient factors before prescribing.
๐ Toxicity + Dose Decision
concentration = 12
age = 65
if concentration > 10:
if age > 60:
print("High toxicity risk โ reduce dose immediately")
else:
print("Moderate toxicity โ monitor patient")
else:
print("Safe concentration")
๐ท Multi-Level Nested Condition
temperature = 104
bp = 150
if temperature > 100:
if bp > 140:
print("Emergency condition")
else:
print("Fever only")
else:
print("Normal condition")
๐ง Memory Trick
- Outer if โ Main decision
- Inner if โ Detailed check
- Think: Step-by-step clinical evaluation
๐งช Practice Exercise
Create a program that:
- Takes patient age and toxicity level
- Gives dose adjustment recommendation
๐ MCQs
- Nested condition means:
a) Loop inside loop
b) If inside if
c) Function inside loop
d) Variable inside function
Answer: b - Which is true about nested conditions?
a) Only one condition allowed
b) Multiple levels possible
c) Cannot use else
d) Only numeric values
Answer: b - Nested conditions are useful for:
a) Simple printing
b) Complex decisions
c) Looping
d) Input
Answer: b
โ FAQs
Why use nested conditions?
They allow handling multiple conditions step-by-step, similar to clinical decision-making.
Are nested conditions difficult?
They are easy if visualized as decision trees.
๐ฅ Download Clinical Decision Tree Exercises
Includes real patient-based scenarios.
โก Next Topic: Loops in Python (for & while) โ
Unit 2 Blog:
- Conditional Statements (if, if-else, if-elif)
- Nested Conditions (clinical decision logic) (You are on this page)
- Loops (for, while) โ repetition in pharma data
- Break & Continue (control flow)
- Functions (definition, arguments, return values)
- Modular Programming (Dose + BMI calculator)
Question Bank Unit 2: Control Structures & Functions
For more details: Basics of Python Programming for Pharmaceutical Sciences