Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. def update(player, direction):
  2.     """Moves the player from its current position one step in the specified
  3.    direction. Returns the players new position.
  4.    
  5.    Args:
  6.        player (tuple): The player position
  7.        direction (str): Either 'N', 'S', 'W', or 'E' representing the four
  8.                         cardinal directions
  9.  
  10.    Returns:
  11.        The new player position (tuple)
  12.  
  13.    """
  14.     # your code for exercise (b)
  15.     playerlist = list(player)
  16.     if direction == "N":
  17.         if playerlist[1] < 4:
  18.             playerlist[1] += 1
  19.     if direction == "E":
  20.         if playerlist[0] < 4:
  21.             playerlist[0] +=1
  22.     if direction == "S":
  23.         if playerlist[1] > 0:
  24.             playerlist[1] -= 1
  25.     if direction == "W":
  26.         if playerlist[0] > 0:
  27.             playerlist[0] -= 1    
  28.     return tuple(playerlist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement