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 | |
|---|---|---|
| 1print(total) # trace | ARe-run a test case after your change to check the function still gives the right result | |
| 2assert area(3, 4) == 12 | BAdd a print line to see what a variable holds while you read and trace someone else's code | |
| 3Change one thing at a time: only edit the 0.10 discount rate to 0.20, then run the program again | CYou must read and trace the code first, then re-run your test cases so you can see the effect of the change. | |
| 4Reading someone else's code: explain what a function does before you edit it | Drate = 0.20 | |
| 5Changed 5 lines of the program, then ran it for the first time | EToo many changes at once. If it breaks, you cannot tell which change caused the error. Change one thing, then re-run. | |
| 6Edited the code without reading it first, and skipped the test cases | F# returns the price after discount |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
modify code — Read and trace the code first to see what it does, then change one small part at a time and re-run your test cases to check the effect of that change.def double(n):
return n * 2
assert double(4) == 8def inc(n):
return n + 1
assert inc(3) == 4def area(w, h):
return w * h
assert area(2, 3) == 6def adult(age):
return age >= 18
assert adult(18) == Truetotal = 0
for n in [1, 2, 3]:
total += n