2024 Exam Question Practice

This is a problem that was given in the 2024 programming exam.
If the character moves left, 5 is subtracted from the position.
If the character moves right, 5 is added to the position.
The position of the character can only be between 1 and 512 inclusive.
The function moveCharacter():
• takes the direction (left or right) and current position as parameters
• changes position based on direction
• sets position to 1 if the new position is less than 1
• sets position to 512 if the new position is greater than 512
• returns the new position.
Complete the function moveCharacter()
def moveCharacter(direction, position):

Scroll to Top