Python Series track

Project 8 · Practice Projects

Project 8 — BMI Tracker

Track BMI over time with a history log, trend analysis, and an ASCII chart of weight progression.

Practice Projects1 min readFree lesson

Difficulty: Lv ★★ | Prerequisites: Basics Week 6, 9 + f-string formatting

Goal

Input BMI of N people → Classification → Display sorted table

Differences from Basic Assignment

  • Basics Week 3 = Calculate BMI for 1 person
  • Here = N people + Classification + Sorting + Statistics

Requirements

  • Exit when done is entered
  • Classification: Underweight (<18.5), Normal (18.523), Overweight (2325), Obese (>=25)
  • Display table in descending order of BMI

Challenge Task

  • Count of people by classification
  • Save as CSV

Assignment

Show the reference solution

Try the assignment yourself first — comparing your attempt with a working solution is where most of the learning happens.

solution.pyPython
"""BMI Tracker — Multi-Person + Sorted Table"""

def classify(bmi):
    if bmi < 18.5: return "Underweight"
    if bmi < 23: return "Normal"
    if bmi < 25: return "Overweight"
    return "Obese"

def main():
    people = []
    print("Enter 'done' in the name field to exit")
    while True:
        name = input("Name:").strip()
        if name.lower() == "done": break
        try:
            h = float(input("Height (cm):"))
            w = float(input("Weight (kg):"))
        except ValueError:
            print("Numbers only"); continue
        bmi = w / (h / 100) ** 2
        people.append({"name": name, "h": h, "w": w, "bmi": bmi})

    if not people:
        return

    people.sort(key=lambda p: -p["bmi"])
    print(f"{'Name':<10}{'Height':>7}{'Weight':>9}{'BMI':>9}  Category")
    for p in people:
        print(f"{p['name']:<10}{p['h']:>7.1f}{p['w']:>9.1f}{p['bmi']:>9.2f}  {classify(p['bmi'])}")

    avg = sum(p["bmi"] for p in people) / len(people)
    print(f"Average BMI: {avg:.2f} ({classify(avg)})")

    #Category-wise Summary
    counts = {}
    for p in people:
        c = classify(p["bmi"])
        counts[c] = counts.get(c, 0) + 1
    print("[By Category]")
    for c in ["Underweight", "Normal", "Overweight", "Obese"]:
        print(f"{c}: {counts.get(c, 0)} people")

if __name__ == "__main__":
    main()

Learn this lesson with a mentor

Work through the Python Series track on your own, or join a guided cohort at our Pitampura campus and online.

Call NowEnroll Now