Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def update(player, direction):
- """Moves the player from its current position one step in the specified
- direction. Returns the players new position.
- Args:
- player (tuple): The player position
- direction (str): Either 'N', 'S', 'W', or 'E' representing the four
- cardinal directions
- Returns:
- The new player position (tuple)
- """
- # your code for exercise (b)
- playerlist = list(player)
- if direction == "N":
- if playerlist[1] < 4:
- playerlist[1] += 1
- if direction == "E":
- if playerlist[0] < 4:
- playerlist[0] +=1
- if direction == "S":
- if playerlist[1] > 0:
- playerlist[1] -= 1
- if direction == "W":
- if playerlist[0] > 0:
- playerlist[0] -= 1
- return tuple(playerlist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement