Functions · Code Improvement

Shape — improve or specify L5 Synthesis Macro Structure ~5 min

Stop repeating the tax calculation

An AI generated this code to show prices with 20% tax. It works but repeats itself. Improve it by removing the duplication, and avoid hiding the 20% inside the formula. You may write code or describe your changes in words.

price1 = 20
total1 = price1 + price1 * 0.2
print("Total:", total1)

price2 = 35
total2 = price2 + price2 * 0.2
print("Total:", total2)

price3 = 50
total3 = price3 + price3 * 0.2
print("Total:", total3)
Why this activity was chosen
  • Bloom level: L5 Synthesis: Improve a working but weak generated solution.
  • Block Model level: Macro Structure (step 4 of 4): the purpose of the whole program: the problem it solves and the goal it serves.
  • Misconception targeted: shown after you answer, so it does not give the answer away.

Synthesis here means revising an existing artefact: names, structure, edge cases. Students start from AI-like output so the task is judgement plus rewriting, not blank-page authorship.

AI’s role here: AI may later comment on the student's revision. It must not hand back a fully rewritten program as the student's answer.