An ice rink report with blank charts and numbers that do not follow the data
Code review · Medium · §10.4 Assembling an HTML report
This AI draft puts two charts of the monthly skaters at two ice rinks, Polar and Glacier, from November to February, and a sentence into the HTML document rink_report.html. When the file is opened on a computer without the internet, both chart spaces are blank, and when it is made again with different skater counts, the two numbers in the paragraph no longer match the charts.
Fix it by changing two lines or fewer so that Plotly.js is inside the file once and the two numbers in the paragraph (with thousands separators) follow totals. Grading changes the skater counts and saves the file again.
Code to fix
from pathlib import Path
import pandas as pd
import plotly.express as px
dates = pd.date_range("2025-11-01", periods=4, freq="MS")
rinks = pd.DataFrame({
"date": list(dates) * 2,
"rink": ["Polar"] * 4 + ["Glacier"] * 4,
"skaters": [820, 1340, 1510, 1180, 640, 990, 1220, 870],
})
totals = rinks.groupby("rink", as_index=False)["skaters"].sum()
line_fig = px.line(rinks, x="date", y="skaters", color="rink", markers=True, title="Skaters per month")
bar_fig = px.bar(totals, x="rink", y="skaters", color="rink", title="Total skaters, November to February")
parts = [line_fig.to_html(full_html=False, include_plotlyjs=False),
bar_fig.to_html(full_html=False, include_plotlyjs=False)]
tot = totals.set_index("rink")["skaters"]
report = f"""<!doctype html>
<html lang="en"><head><meta charset="utf-8"><title>Ice rink report</title></head>
<body>
<h1>Ice rink report</h1>
<p>From November to February, Polar had 4,850 skaters and Glacier had 3,720 skaters.</p>
{parts[0]}
{parts[1]}
</body></html>"""
Path("rink_report.html").write_text(report, encoding="utf-8")Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.