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 | |
|---|---|---|
| 1Average <- Total / Count | AChecks that at least one value was entered, so the program never divides by zero | |
| 2IF Count > 0 THEN | BENDWHILE IF Count > 0 THEN Average <- Total / Count ENDIF | |
| 3Total and Count are both updated in the same loop, once for each value entered | CThere is no check that Count is above 0. If the user enters no values, the program divides by zero. It needs IF Count > 0 THEN around the calculation. | |
| 4The average is calculated once, after the loop has ended, and only if Count is above 0 | DThe average is calculated inside the loop, so it is recalculated every time instead of once at the end. It should come after ENDWHILE. | |
| 5WHILE Number <> -1 DO Total <- Total + Number Count <- Count + 1 Average <- Total / Count INPUT Number ENDWHILE | EDivides the running total by the number of values to find the mean, after the loop has finished | |
| 6Average <- Total / Count OUTPUT Average | FTotal <- Total + Number Count <- Count + 1 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
Average <- Total / Count — After the loop ends, divide the total by the count to get the mean. Check that Count > 0 first, so the program never divides by zero.Average <- Total / CountIF Count > 0 THEN
Average <- Total / Count
ENDIFTotal <- Total + Mark
Count <- Count + 1ENDWHILE
IF Count > 0 THEN
Average <- Total / CountAverage <- Total / Count
OUTPUT "Average: ", Average