Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
Question 25

A student is writing a Mars Rover simulation in Python.

Figure 1

0123456
SS

Figure 2

  • The rover starts at position 0 in a list of sectors representing a path.
  • The aim of the simulation is for the rover to reach the final index in the list (representing the science station).
  • At each turn, the operator must enter either 1 or 3 to command the rover to move forward by that many sectors:
    • Entering 1 increases the rover's position by 1.
    • Entering 3 increases the rover's position by 3.
  • If the rover's position goes beyond the end of the list (overshoots) or lands on a sand trap (marked by 'S'):
    • the message Stuck! is displayed
    • the rover's position is reset back to 0
  • These steps are repeated until the rover reaches the final index of the list.

Figure 3

position = 0
final_sector = len(path) - 1
while position < final_sector:

Extend the program from Figure 3 so that the simulation works as described in Figure 2.

When writing your program you should assume:

  • there is a list called path
  • the number of 'S' characters in path can vary
  • the position of the 'S' characters in path can vary
  • the 'S' characters have already been added to the list called path
  • the path list can be of any length.

You should use indentation as appropriate, meaningful variable name(s), and Python syntax in your answer.

[8]
Markscheme

Programming concepts Questions

  1. GCSE
  2. /Computer Science
  3. /Programming concepts

298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank