The check output of a flower shop report with a cdn piece put in twice

Predict the output · Challenge · §10.5 Reviewing the report

The code makes a report file from a weekly sales line chart and a bar chart of totals for a flower shop, then reads the saved file back to check it. Predict the four lines of output without running the code.

Code

from pathlib import Path

import pandas as pd
import plotly.express as px

shop = pd.DataFrame({
    "week": [1, 2, 3, 4] * 2,
    "flower": ["Roses"] * 4 + ["Tulips"] * 4,
    "bunches": [30, 42, 38, 51, 25, 20, 33, 29],
})
weekly = px.line(shop, x="week", y="bunches", color="flower", title="Bunches sold per week")
total = px.bar(shop.groupby("flower", as_index=False)["bunches"].sum(), x="flower", y="bunches",
               title="Total bunches")
parts = [weekly.to_html(full_html=False, include_plotlyjs="cdn"),
         total.to_html(full_html=False, include_plotlyjs=False)]
path = Path("flowers.html")
path.write_text(f"<h1>Flower shop</h1>\n{parts[0]}\n<h2>Total</h2>\n{parts[0]}\n", encoding="utf-8")

html_text = path.read_text(encoding="utf-8")
print(html_text.count('class="plotly-graph-div"'))
print(html_text.count("plotly.js v"))
print(html_text.count(" src="))
print(sum(len(t.x) for t in weekly.data))

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.