(a)

def main():
      maze= open('maze.txt','r+')
      for line in maze:
          line = line.strip()
          print line
       maze.close()
print
start(maze,x,y)
print maze[y][x]

(b)

def start(maze,x,y):
         for x in range(0,len(maze)):
                 if maze[y][x] == "s"
                 print maze[y][x]
                 return x, y

question (b): write a function that walks through the maze and attempts to find exit. As a minimum, the function should accept two argument that specify the starting row and column number.

Edited 6 Years Ago by Nick Evan: added code tags

def main():
      maze= open('maze.txt','r+')
      for line in maze:
          line = line.strip()
          print line
       maze.close()
print
start(maze,x,y)
print maze[y][x]

This code won't run. You don't call main() and neither maze, x, or y are defined before calling the start(maze, x, y) function. "How To Think Like A Computer Scientist" is a good learning tool; "Functions" Chapter (3.5) = http://www.greenteapress.com/thinkpython/html/book004.html

Edited 6 Years Ago by woooee: n/a

Maze = [ [ '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' ],\
[ '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' ],\
[ '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' ],\
[ '.','.','.','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' ],\
[ '#','#','.','#','#','.','.','#','#','#','#','#','#','#','#','#','#','#','#','#' ],\
[ '#','#','.','#','#','.','.','#','#','#','#','#','#','#','#','#','#','.','.','.' ],\
[ '#','#','.','#','#','.','.','#','#','#','#','#','#','#','#','#','#','.','#','#' ],\
[ '#','#','.','.','.','.','#','#','#','#','#','#','#','#','#','#','#','.','#','#' ],\
[ '#','#','.','#','#','.','#','#','#','#','#','#','.','.','.','.','.','.','#','#' ],\
[ '#','#','.','#','#','.','#','#','#','#','#','#','.','#','#','#','#','.','#','#' ],\
[ '#','#','.','#','#','.','#','#','#','#','#','#','.','#','#','#','#','.','#','#' ],\
[ '#','#','#','#','#','.','.','.','.','.','.','.','.','#','#','#','#','#','#','#' ],\
[ '#','#','#','#','#','#','#','#','#','#','#','#','.','#','#','#','#','#','#','#' ],\
[ '#','#','#','#','#','#','#','#','#','#','#','#','.','#','#','#','#','#','#','#' ],\
[ '#','#','#','#','#','#','#','#','#','#','#','#','.','#','#','#','#','#','#','#' ],\
[ '#','#','#','#','#','#','#','#','#','#','#','#','.','#','#','#','#','#','#','#' ],\
[ '#','#','#','#','#','#','#','#','#','#','#','#','.','#','#','#','#','#','#','#' ],\
[ '#','#','#','#','#','#','#','#','#','#','#','#','.','#','#','#','#','#','#','#' ],\
[ '#','#','#','#','#','#','#','#','#','#','#','#','.','#','#','#','#','#','#','#' ],\
[ '#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' ],\
]

def PrintMaze():
global Maze
return Maze

print(PrintMaze())

I got dis, but I am not sure how to print Maze in rows shown above. it is coming as a single line.

Edited 6 Years Ago by adam321: n/a

def maze_to_string(maze):
    return "\n".join(''.join(row) for row in maze)

print maze_to_string(Maze)

"""my output --->
####################
####################
####################
...#################
##.##..#############
##.##..##########...
##.##..##########.##
##....###########.##
##.##.######......##
##.##.######.####.##
##.##.######.####.##
#####........#######
############.#######
############.#######
############.#######
############.#######
############.#######
############.#######
############.#######
####################

# if you replace '' with ' ', you get

# # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # #
. . . # # # # # # # # # # # # # # # # #
# # . # # . . # # # # # # # # # # # # #
# # . # # . . # # # # # # # # # # . . .
# # . # # . . # # # # # # # # # # . # #
# # . . . . # # # # # # # # # # # . # #
# # . # # . # # # # # # . . . . . . # #
# # . # # . # # # # # # . # # # # . # #
# # . # # . # # # # # # . # # # # . # #
# # # # # . . . . . . . . # # # # # # #
# # # # # # # # # # # # . # # # # # # #
# # # # # # # # # # # # . # # # # # # #
# # # # # # # # # # # # . # # # # # # #
# # # # # # # # # # # # . # # # # # # #
# # # # # # # # # # # # . # # # # # # #
# # # # # # # # # # # # . # # # # # # #
# # # # # # # # # # # # . # # # # # # #
# # # # # # # # # # # # # # # # # # # #

"""

Edited 6 Years Ago by Gribouillis: n/a

How can I move to row 4 and replace it with x, and move forward to col 2 of row 4.

x= "x"
Squares= 399
def start():
for i in range(squares):
Maze.append(x)
return Maze
print"\n\t", Maze[60], ",", Maze[61], ",", Maze[62]

print(start())

I am getting invalid sytamic for "\n\t"

This question has already been answered. Start a new discussion instead.