Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON DATA / CHAPTER 02 / Learn / LESSON 06
Fifth class — Data finale. We do not learn new syntax. We assemble a report: one dict that holds the key metrics of the health log.
report collects: - count — how many measurements (len(weights)) - average — mean weight (sum / len) - latest_bmi — BMI from the latest weight: weights[-1] / height ** 2
Index -1 in Python means “the last item”. Handy when the log grows — you always take the newest weight without memorizing the length.
Once report is ready, the console should announce readiness and show the numbers. The string "DATA READY" is the lab signal (and your dashboard cue) that the report is assembled.
Mini thinking structure:
height = …
weights = […]
average = …
latest_bmi = weights[-1] / height ** 2
report = {"count": …, "average": …, "latest_bmi": …}
print("DATA READY")
# then print count, average, round(latest_bmi, 2)Common mistake: hardcoding numbers into report instead of computing them; forgetting "DATA READY"; writing weights[4] instead of weights[-1] (brittle if length changes).
Learn: you write the variables and report; formulas are in the hint.
DATA LAUNCH STANDBY
›