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 | |
|---|---|---|
| 1FOR Count ← 1 TO 5 | AOPENFILE is inside the loop. WRITE mode replaces the old data each time, so only the last score is kept. It should go before the loop. | |
| 2WRITEFILE "Scores.txt", Score | BStarts a loop that repeats its body exactly five times, so five items can be written to the file. | |
| 3The file is opened for writing once, before the loop starts. | CINPUT Name WRITEFILE "Names.txt", Name | |
| 4Inside the loop, each item is input and then written to the file. | DWrites the value just entered into the open file. Inside the loop, this happens on every repeat. | |
| 5FOR Count ← 1 TO 5 INPUT Score WRITEFILE "Scores.txt", Score CLOSEFILE "Scores.txt" NEXT Count | EOPENFILE "Names.txt" FOR WRITE FOR Count ← 1 TO 5 | |
| 6FOR Count ← 1 TO 5 OPENFILE "Scores.txt" FOR WRITE INPUT Score WRITEFILE "Scores.txt", Score NEXT Count | FCLOSEFILE is inside the loop, so the file is closed after the first score and the next WRITEFILE fails. It should go after NEXT Count. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
FOR Count ← 1 TO 5 — A FOR loop with INPUT and WRITEFILE inside repeats a fixed number of times, writing one item to the open file on each repeat. CLOSEFILE goes after NEXT.OPENFILE "Scores.txt" FOR WRITE
FOR Count ← 1 TO 5
INPUT ScoreFOR Count ← 1 TO 5
INPUT Score
WRITEFILE "Scores.txt", ScoreFOR Count ← 1 TO 5
INPUT Name
WRITEFILE "Names.txt", Name WRITEFILE "Scores.txt", Score
NEXT Count
CLOSEFILE "Scores.txt" WRITEFILE "Scores.txt", Score
NEXT Count
CLOSEFILE "Scores.txt"