string - Show user position on 2D maze - Python -


i have task must print maze provides user's position. position can dependent on generated position function. mean position can have many different possibilites.

i tried use slicing combination of .replace method able change character user's position symbolled 'a'.

see code below, doing wrong here?

def print_maze(maze, position): """ returns maze string text file , position of player  print_maze(str, int) -> object """  p1 = position[0] p2 = position[1] position = position_to_index((p1,p2), len(maze))  line in maze:     maze = maze[:position].replace(' ', 'a') + maze[position:]      line in maze:         maze.strip().split('\n')  print(maze) 

for result far, is:

>>> maze = load_maze('maze1.txt') >>> print_maze(maze, (1,1)) ##### #aaz# #a### #aap# ##### 

it seems you're making harder need be. rather load maze 1 string, read array. .strip() 1 in load_maze rather every call print-maze():

def load_maze(filename):     """     returns maze string text file      load_maze(str) -> list     """     maze = []     open(filename) file:         line in file:             maze.append(line.strip())     return maze  def print_maze(maze, position):     """     prints maze position of player      print_maze(str, (int, int)) -> none     """      (x, y) = position      row, line in enumerate(maze):         if row == y:             print(line[:x] + 'a' + line[x + 1:])         else:             print(line)  maze = load_maze('maze1.txt')  print_maze(maze, (1, 1)) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -