An algorithm is intended to display eight planets from a list in reverse order (starting with 'Neptune' and ending with 'Mercury'). However, the algorithm currently contains logic errors.
Figure 1
1 SUBROUTINE getPlanet(planets)
planets ← ['Mercury', 'Venus', 'Earth', 'Mars',
2 'Jupiter', 'Saturn', 'Uranus', 'Neptune']
3 RETURN planets[pos]
4 ENDSUBROUTINE
5
6 FOR i ← 8 TO 0 STEP 1
7 OUTPUT(getPlanet(i))
8 ENDFOR
Rewrite line 1 and line 6 from Figure 1 to make the algorithm work as intended.
Practise AQA GCSE Computer Science Structured programming and subroutines (procedures and functions) with exam-style questions for GCSE Computer Science. 100 questions, matched to the AQA GCSE Computer Science (8525) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.