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 | |
|---|---|---|
| 1TAX_RATE = 0.1 | AA small function that does one job, so it can be fixed or reused without affecting other code | |
| 2def calculate_total(items): | Bprice = base * (1 + GST_RATE) | |
| 3A class can hide its detail by keeping data private, so other code uses methods instead of changing it directly | CA constant that stores a value once, so it can be changed in one place instead of many | |
| 4Replace a repeated number with a named constant so a future change is made in one place | Dself.__balance = 0 | |
| 5total = cost * 0.1 + fee * 0.1 + tip * 0.1 | EThe value 0.1 is repeated (a magic number). If the rate changes, every copy must be found and edited. Store it once as a constant such as RATE. | |
| 6def do_everything(): read_input() calc_marks() print_report() | FOne big function does many jobs, so a change to one job can break the others. Split it into small functions that each do one job. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
maintainable code — Code organised so it can be fixed or extended later without breaking other parts, using small functions, classes that hide detail and constants instead of repeated values.def total(price, qty):
return price * qtyRATE = 0.1
total = price * (1 + RATE)class Account:
def getBalance(self):
return self.balanceclass Account:
def getBalance(self):
return self.balancePASS = 50
def isPass(mark):
return mark >= PASS