Hide

Problem B
Move

Languages en is

Write a program that asks the user for the position of a virtual character on the x-axis in a coordinate system and then allows the user to move the virtual character to the right or left, indicated by the characters r or l. The user should be able to move the virtual character as often as they wish, but if the input is neither r nor l the program quits. The new position of the virtual character and instructions for the user are written out in each iteration.

The valid range on the $x$-axis, which the virtual character can traverse, is from $1$ to $10$. If the virtual character is positioned at either end of the range it will not move when the user tries to move it out of the range.

Further information about the implementation:

  1. If the initial position of the virtual character is not bertween $1$ and $10$, the program should ask the user again until the position is valid.

  2. The current position is shown as o, while other positions on the $x$-axis are shown as x.

  3. You should implement the numbers $1$ and $10$ and the characters r and l as constants. In Python, a constant is a variable whose value will not change during execution of the program. It is a good rule to use capital letters for naming constants.

  4. You should use functions in your implementation. It is fine that your main program contains the loop, but the body of the loop should, in most part, be a series of function calls.

Scoring

Group

Points

Constraints

1

10

No invalid starting positions and no moves made.

2

10

No moves made.

3

10

No invalid starting positions, only left moves, and never attempted to cross the edges.

4

10

No invalid starting positions, only right moves, and never attempted to cross the edges.

5

10

No invalid starting positions and never attempted to cross the edges.

6

10

No invalid starting positions, only left moves.

7

10

No invalid starting positions, only right moves.

8

10

No invalid starting positions.

9

10

Never attempted to cross the edges.

10

10

No further constraints.

Read Sample Interaction 1 Write
Position in [1..10]: 
0
Position in [1..10]: 
11
Position in [1..10]: 
7
xxxxxxoxxx
l: left
r: right
Move: 
r
xxxxxxxoxx
l: left
r: right
Move: 
r
xxxxxxxxox
l: left
r: right
Move: 
l
xxxxxxxoxx
l: left
r: right
Move: 
r
xxxxxxxxox
l: left
r: right
Move: 
r
xxxxxxxxxo
l: left
r: right
Move: 
r
xxxxxxxxxo
l: left
r: right
Move: 
q