Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8.
Run the algorithm one line at a time and only write a value when it changes. Each table scores 2 marks.
MYWORD: it is too short (6 characters) and all upper case, so Accept becomes FALSE twice. The loop is skipped and Rejected is output.
| Password | Accept | Index | Found | OUTPUT |
|---|---|---|---|---|
| MYWORD | TRUE | (Please enter password) | ||
| FALSE | ||||
| FALSE | ||||
| 1 | FALSE | |||
| FALSE | Rejected |
Password and OUTPUT correct [1]
Accept, Index and Found columns correct [1]
M!word: it is too short, so Accept becomes FALSE. It has mixed case, so line 08 changes nothing. The loop does not run, then NOT Found sets Accept to FALSE.
| Password | Accept | Index | Found | OUTPUT |
|---|---|---|---|---|
| M!word | TRUE | (Please enter password) | ||
| FALSE | ||||
| 1 | FALSE | |||
| FALSE | Rejected |
Password and OUTPUT correct [1]
Accept, Index and Found columns correct [1]
My!Hidden: it is 9 characters with upper and lower case, so Accept stays TRUE. The loop finds ! at Index 3, so Found becomes TRUE and Index becomes 4.
| Password | Accept | Index | Found | OUTPUT |
|---|---|---|---|---|
| My!Hidden | TRUE | (Please enter password) | ||
| 1 | FALSE | |||
| 2 | FALSE | |||
| 3 | TRUE | |||
| 4 | ||||
| Accepted |
Password and OUTPUT correct [1]
Accept, Index and Found columns correct [1]
Work out the rules from the IF statements.
The length must be at least 8 and no more than 20 characters [1]
It cannot be all upper case or all lower case (it must have both) [1]
It must contain an ! [1]
▶ Topic lesson
A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.