Project 8 — BMI Tracker
Track BMI over time with a history log, trend analysis, and an ASCII chart of weight progression.
What you'll learn
- 1Calculate BMI and classify the result
- 2Store daily measurements in JSON
- 3Plot weight history as an ASCII chart
- 4Compute 7-day and 30-day trends
BMI Categories
| BMI | Category |
|---|---|
| < 18.5 | Underweight |
| 18.5–24.9 | Normal |
| 25–29.9 | Overweight |
| ≥ 30 | Obese |
Sample Output
Date: 2024-05-01
Weight (kg): 72.5
Height (cm): 175
BMI: 23.67 — Normal
Weight History (last 7 days):
2024-04-25 |████████████████████ 74.0
2024-04-28 |███████████████████ 73.2
2024-05-01 |██████████████████ 72.5
Trend: ↓ 1.5 kg over 6 daysCommon Mistakes (FAQ)
Q. My BMI comes out as ~7700 — what's wrong?
You used height in centimeters. BMI = kg / m², so convert first: 175 cm → 1.75 m, then bmi = weight / (1.75 ** 2). Dividing by 175² instead of 1.75² is the classic bug.
Q. The program crashes when I type the weight.
float(input()) raises ValueError on non-numeric input. Wrap it in try/except ValueError and re-prompt, so a stray letter or empty line doesn't kill the session.
Q. How do I avoid a ZeroDivisionError?
Guard the height before dividing: if height_m <= 0, ask again. A height of 0 (or a blank that you coerced to 0) is the only way to hit it.
Q. Which category does exactly 25.0 fall into?
Decide your boundaries explicitly: < 18.5 Underweight, 18.5–24.9 Normal, 25–29.9 Overweight, ≥ 30 Obese. Use >= for the lower edge of each band so 25.0 is Overweight, and document it — boundary handling is the most common grading miss.
Q. How do I scale the ASCII bar chart?
Scale each bar to the max weight in the window: bar_len = round(w / max_w * WIDTH), then print '█' * bar_len. Don't scale to a fixed number or short series look identical.
📝 Exercises
Try them yourself first, then open the solution to compare.
Build the BMI tracker
Goal: Implement measurement recording, BMI calculation, and ASCII chart.
- Record weight+height+date
- BMI and category
- JSON history
- ASCII weight chart
All lecture materials and example code are openly available on GitHub.
View on GitHub ↗