Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1CONSTANT VatRate ← 0.2 | AGives the number 0.2 a meaningful name, so later lines can use VatRate instead of an unexplained magic number | |
| 2Total ← Price * VatRate | BCONSTANT VatRate ← 0.25 | |
| 3A magic number in a calculation is hard to understand, because the reader cannot tell what 0.2 stands for | CThe rate 0.2 is typed as a magic number on every line. When the rate changes, every line must be edited, which is slow and easy to get wrong. | |
| 4Changing a rate once: edit only the CONSTANT line and every calculation using the name gets the new value | DUses the named constant in a calculation, so if the rate changes only the CONSTANT line needs editing | |
| 5Tax1 ← Price1 * 0.2 Tax2 ← Price2 * 0.2 Tax3 ← Price3 * 0.2 | EOne line was missed when the rate was updated, so the program uses two different rates and gives wrong results. | |
| 6Tax1 ← Price1 * 0.25 Tax2 ← Price2 * 0.2 Tax3 ← Price3 * 0.25 | FTax ← Price * 0.2 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
CONSTANT VatRate ← 0.2 — A named value used instead of a magic number. It makes code easier to read, and when the value changes you edit it in one place only, so no missed edits cause mistakes.CONSTANT VatRate ← 0.2
Tax ← Price * VatRateCONSTANT VatRate ← 0.2
Tax ← Price * VatRateCONSTANT VatRate ← 0.2
Tax ← Price * VatRate
OUTPUT TaxCONSTANT VatRate ← 0.2
Tax ← Price * VatRateCONSTANT VatRate ← 0.25
Tax1 ← Price1 * VatRate
Tax2 ← Price2 * VatRate