Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would i be able to bypass this when defining it as a function (maze at the very top is what i need to show)?

How would i be able to bypass this when defining it as a function (maze at the very top is what i need to show)? And how would i go about it in def maze_read to solve without using strips? (please don't use strips in either one)

in python please

code:

import check_input

def read_and_display_maze():

f = open("maze.txt") content = f.read() print(content) print()

def read_maze():

maze = [] file = open("maze.txt") for line in file: s = [] for a in line.strip(): s.append(a) maze.append(s) return maze def find_start(maze):

for i in range(len(maze)): for j in range(len(maze[i])): if maze[i][j] == "s": return [i,j] def display_maze(maze, loc):

for i in range(len(maze)): for j in range(len(maze[i])): if i == loc[0] and j == loc[1]: print("x", end="") else: print(maze[i][j], end="") print() def main(): print("-Maze Solver-") print() maze = read_maze() loc = find_start(maze) while maze[loc[0]][loc[1]] != 'f': display_maze(maze, loc) print() print("1. Go North") print("2. Go South") print("3. Go East") print("4. Go West") option = check_input.get_int_range("Enter choice: ", 1, 4)

if option == 1: if maze[loc[0]-1][loc[1]] != '*': loc[0] -= 1 else: print("You cannot move there.") elif option == 2: if maze[loc[0]+1][loc[1]] != '*': loc[0] += 1 else: print("You cannot move there.") elif option == 3: if maze[loc[0]][loc[1]+1] != '*': loc[1] += 1 else: print("You cannot move there.") elif option == 4: if maze[loc[0]][loc[1]-1] != '*': loc[1] -= 1 else: print("You cannot move there.")

display_maze(maze, loc) print("Congratulations! You solved the maze.") main()

image text in transcribedimage text in transcribed

image text in transcribedmaze.txt file

main.py maze - Notepad File Edit View * * 5f

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Use a three-step process to develop effective business messages.

Answered: 1 week ago