A command-line Python simulator for modeling bacterial population dynamics across discrete generations under baseline growth and mortality conditions, with optional antibiotic intervention.
The Bacterial Growth Simulator models changes in bacterial population size over time using user-defined growth and death rates.
The simulation progresses one generation at a time. An optional antibiotic intervention can be introduced at a user-specified generation, applying an additional mortality rate from that point onward.
The project is designed as a lightweight computational model for exploring how population-level parameters affect bacterial growth and decline.
- User-defined initial bacterial population
- Configurable bacterial growth rate
- Configurable baseline death rate
- Generation-by-generation population simulation
- Optional antibiotic intervention
- User-defined antibiotic introduction generation
- User-defined antibiotic-induced mortality
- Input validation and error handling
- Support for percentage inputs with or without
% - Final population and total population change reporting
Under normal conditions, the population is updated using:
N{t+1} = Nt(1 + {r-d}/100)
where:
- (N_t) = population at generation (t)
- (r) = growth rate (%)
- (d) = baseline death rate (%)
When an antibiotic is active, the model uses:
N{t+1} = Nt(1 + {r-d-a}/100)
where:
- (a) = additional antibiotic-induced mortality (%)
The population from each generation becomes the starting population for the following generation.
Initial Population: 100
Growth Rate: 20
Death Rate: 5
Number of Generations: 5
Do you want to introduce an antibiotic? (yes/no): yes
Enter the generation you would like to introduce the antibiotic: 3
Antibiotic death rate: 80
========== Bacterial Growth Simulator ==========
Generation 0: 100
Generation 1: 115
Generation 2: 132
Generation 3: 46
Generation 4: 16
Generation 5: 6
========== Simulation Complete ==========
Initial Population: 100
Final Population: 6
Change: -94
This simulator is a simplified deterministic population model and is not intended to predict real bacterial population behavior.
The current model assumes:
- Population dynamics occur in discrete generations.
- Growth and baseline mortality rates remain constant throughout the simulation.
- Antibiotic mortality represents additional mortality beyond baseline mortality.
- The antibiotic begins affecting the population at the specified generation.
- Total baseline and antibiotic mortality cannot exceed 100%.
- The population is represented as a single homogeneous population.
The model does not currently account for:
- Nutrient limitation or carrying capacity
- Bacterial mutation
- Antibiotic resistance
- Bacterial subpopulations
- Antibiotic concentration or pharmacokinetics
- Environmental conditions
- Stochastic population dynamics
- Species-specific biological parameters
The simulator validates user input before running the simulation.
| Parameter | Constraint |
|---|---|
| Initial population | > 0 |
| Growth rate | 0–100% |
| Baseline death rate | 0–100% |
| Number of generations | > 0 |
| Antibiotic generation | Within simulation range |
| Antibiotic mortality | 0–(100 − baseline death rate)% |
Invalid numeric input is handled using Python exception handling rather than terminating the program.
- Python 3
- Command-line interface
- No external Python libraries
bacterial-growth-simulator/
│
├── bacterial_growth.py
└── README.md
Clone the repository and run:
python bacterial_growth.pyThe program will prompt for the simulation parameters and display the population at each generation.
The project demonstrates several core Python programming concepts:
- Variables and data types
- User input and formatted output
- Conditional logic
whileloops- Exception handling with
try/except - Input validation
- String manipulation
- Functions
- Iterative state updates
- Basic mathematical modeling
This project focuses on implementing a simple population model rather than reproducing the complexity of real bacterial systems.
Its primary purpose is to demonstrate how a biological process can be translated into a computational model and simulated programmatically.
This project is available for educational and personal use.