Project Background

Building a Health Metrics Calculator

Creating multiple Python functions that calculates BMI, BMR, and calorie targets in one unified tool

Part 1 of 2: Back-End Function Development

TL;DR

I built a modular calculation engine using Python, that calculates 7 key health metrics from 5 user inputs (weight, height, age, sex, activity level). The functions use the Mifflin-St Jeor equation for BMR calculations and activity multipliers for calorie targets. By designing each metric as an independent function, the code is easier to manage and debug.

The Objective

Online health calculators are everywhere, but most only compute one metric at a time. Want your BMI? One website. Maintenance calories? Another. Protein intake? A third. This fragmented experience forces users to re-enter the same data repeatedly across multiple tools.

Goal: Can I build a unified calculator that takes a user's information and returns all their key health metrics

Formulas & Context

BMI Formula: Weight (kg) ÷ Height (m)²
BMR Formula: Mifflin-St Jeor equation (more accurate than Harris-Benedict for modern populations)
Exercise Level: 1.2 (sedentary) to 1.9 (super active)
Limitations: Currently metric-only (kg/cm). Imperial unit would be included in a future iteration.

Metrics Calculated

The calculator computes seven interconnected health metrics from a single set of inputs:

BMI
Body Mass Index
BMR
Basal Metabolic Rate
Maintenance
Daily calories to maintain weight
Mild Loss
90% of maintenance (0.25kg/week)
Moderate Loss
79% of maintenance (0.5kg/week)
Extreme Loss
58% of maintenance (1kg/week)
Protein
Daily intake in grams

My Approach

I chose a modular function-based codebase because it keeps each calculation isolated, testable, and reusable. Rather than one complex function, each metric has its own dedicated function that can be called independently.

1
Built functions first: Starting with BMI, then BMR (adds sex and age), then maintenance calories (adds activity level). Each function handles one calculation only.
2
Added sex-specific calculations: The Mifflin-St Jeor equation differs for males and females, so the BMR function uses conditional logic to apply the correct formula based on user input.
3
Created weight loss variants: Built three calorie deficit functions (mild/moderate/extreme) that apply percentage reductions to maintenance calories.
4
Aggregated into a master function: Created a single entry point that collects all inputs once, calls each calculation function and returns a formatted output string.
Key decision: I intentionally duplicated the BMR calculation inside each calorie function rather than nesting function calls. This makes each function fully self-contained, which helps with debugging, future refactoring & GUI implementation.
Health metrics output in Python console
Figure 1: Sample Output Output string from the final combined function, taking 5 inputs and returning all 7 health metrics. This output structure will feed directly into the GUI in Part 2.

Key Outcomes

7 Metrics from 5 Inputs

The aggregated function requires only weight, height, age, sex, and activity level, and returns BMI, BMR, maintenance calories, three weight loss targets, and protein intake.

Activity Level is Highly Weighted

The difference between sedentary (1.2×) and super active (1.9×) multipliers can mean 800+ calories/day difference in maintenance needs for the same person.

Designed for Testing

Each function can be tested independently, making it easy to verify calculations.

What's Next: With the calculation engine built, Part 2 will wrap this logic in a user-friendly Tkinter GUI. Allowing users to input their data through form fields and see results update in real time.

Continue to Part 2: GUI Development

Reflection

This project was my first time building back-end logic for an application, using modular functions has kept things easy to follow and easier to debug.

If I was to revisit this project, I would add input validation to my functions. This would stop users inputting negative values. I'd also add the option for metric and imperial (similar to current online tools). I would also like to increase the number of health metrics calculated, such as body fat percentage.

Tools & Technologies

Python Modular Functions Mifflin-St Jeor Equation Conditional Logic