Concept Explanation
This lesson turns a small business problem into a simple Python script. Imagine someone on your team sends you a few daily sales numbers and asks for a quick summary: How many days do we have, what was the best day, what was the weakest day, and what does the average look like? That is the kind of task Python is very good at. You do not need a big framework for it. You just need clean inputs, a function that calculates the values you care about, and an output line that another person can understand without reading the code. By the end of this lesson, you will be able to: • take a small list of sales values and summarize it clearly, • separate calculation from display so the code stays easy to reuse, • handle the empty-data case without crashing the script. Why this matters: beginner programmers often learn syntax in isolation, but real work usually starts with small summaries like this. A script that answers one practical question is already much more useful than a random demo.
Where to Put the Code
- Define color and position variables at the top.
- Create shape drawing or placement logic in the middle.
- Render output (print, canvas, SVG, or styled block) at the end.
Command Reference
- Keep the calculation inside one function so you can reuse it later with file data or API data.
- Store the sales numbers in a list first, then calculate the summary from that list.
- Return a readable string from the helper function instead of printing from several places.
- Always decide what the script should do when there is no data before you worry about extra features.
Step-by-step Guide
- Run the script once and read the summary line carefully from left to right.
- Change one sales value in `week_sales`, run the file again, and note which part of the summary changed.
- Replace the sample list with your own four numbers and make sure the report still makes sense.
- Add a second print line that calls `build_sales_report([])` so you can see how the empty-data case behaves.
- Write one short note explaining why the reporting function returns text instead of printing directly.
Practice Exercises
- Change the output so it also includes the total sales for the week.
- Create a version of the data where one day has a very low value and explain how it affects the average.
- Rewrite the final report line in your own wording while keeping the same numbers.
Coding Challenges
- Raise a `ValueError` if any sales number is negative and make the error message easy to understand.
- Return the summary as a dictionary first, then build the final text from that dictionary in a separate step.
Mini Practice Tasks
- Rename `week_sales` to another clear name and keep the script readable.
- Test the function with a list that contains only one value.
- Write one line of future work, such as reading sales numbers from a CSV file later.
Common Mistake
Mixing x and y axes or using wrong coordinate origin causes shapes to appear in unexpected places.
Real-life Mini Challenge
Draw one square, one triangle, and one circle, then move X marker 2 steps right and 1 step down.