×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Python Program to Implement Maze Assignment Solution

June 25, 2024
Dr. Matthew Hernandez
Dr. Matthew
🇨🇭 Switzerland
Python
Dr. Matthew Hernandez, an esteemed Computer Science researcher, obtained his PhD from ETH Zurich, Switzerland. With 6 years of experience under his belt, he has successfully completed over 400 Python assignments, demonstrating his proficiency and commitment to excellence.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Familiarize yourself with OCaml's pattern matching; it simplifies handling recursive data structures like lists and trees, making your code concise and easier to debug.
News
In 2024, Girls Who Code introduced a Data Science + AI track in their free summer programs for high school students, fostering skills in cybersecurity and creative coding​

Instructions

Objective

To complete a Python assignment, you can write a program to implement a maze in Python. Creating a maze-solving algorithm can be a challenging and rewarding task. You'll need to design the maze structure, implement the necessary functions to navigate through it, and possibly employ search algorithms like depth-first search or breadth-first search to find a path from the start to the end of the maze. This assignment will not only test your programming skills but also your problem-solving abilities. Make sure to plan your approach, break down the problem into manageable steps, and test your code thoroughly to ensure it works correctly.

Requirements and Specifications

program-to-implement-maze-in-python

Source Code

import random # define your Maze class here class Maze: def __init__(self, N=4, p=0.3, maze_style='basic'): # Ensure that N is in [4,8] if N < 4: N = 4 elif N > 8: N =8 self.N = N # Ensure that P is in [0, 1) if p < 0: p = 0 elif p >= 1: p = 0.5 if maze_style != 'basic' and maze_style != 'xspace': maze_style = 'basic' self.p = p self.maze_style = maze_style def gen_maze(self): ''' Randomly generate an embedded list with N sublists, each of which has N integer elements with values either 0 or 1. For example, if N = 4, the generated list named maze could be [[0, 0, 1, 0], [1 0, 0, 1], [0, 1, 0, 0], [1 0, 0, 0]]. The starting point is at maze[0][0], and the end point is at maze[N-1][N-1]. ''' self.maze = [] # initialization the embedded list # implement the gen function here (2 marks) for i in range(self.N): # Create a sublist of N elements with random 0 and 1 sublist = [] for j in range(self.N): # Generate random number x = random.random() if x <= self.p: x = 1 else: x = 0 sublist.append(x) # If the current index is zero, then set the elment (0,0) as 0 if i == 0: sublist[0] = 0 elif i == self.N-1: # if the current index is N-1 then set the element (N,N) to 0 sublist[-1] = 0 self.maze.append(sublist) def print_maze(self): """ Print the maze on the screen (standard output). """ print('maze style is: ' + self.maze_style) # write your code below (2 marks) if self.maze_style == 'basic': print(self.maze) elif self.maze_style == 'xspace': for i in range(self.N): row = self.maze[i] for j in range(self.N): if (i == 0 and j == 0) or (i == self.N-1 and j == self.N-1): print('*', end = "") else: if self.maze[i][j] == 0: print('O', end='') else: print('X', end='') print() print('Done!') cout << "Enter number of hours: "; cin >> hours; if(hours > 0) { break; } else { cout << "Please enter a positive number of hours." << endl; } } // Now, calculate double monthly_cost; double hour_cost; double total_cost; int max_hours; if(package_name.compare("A") == 0 || package_name.compare("a") == 0) { monthly_cost = 9.95; hour_cost = 2.00; max_hours = 10; total_cost = monthly_cost; // Calculate if(hours > max_hours) { total_cost = monthly_cost + (hours - max_hours)*hour_cost; } } else if(package_name.compare("B") == 0 || package_name.compare("b") == 0) { monthly_cost = 13.95; hour_cost = 1.00; max_hours = 20; total_cost = monthly_cost; // Calculate if(hours > 120) { total_cost = monthly_cost + (hours - max_hours)*hour_cost; } } else // it is package C { monthly_cost = 19.95; hour_cost = 0.00; total_cost = monthly_cost; } // Finally, display cout << "Your total bill for this month is: $" << total_cost << endl; }

Similar Samples

Explore our diverse array of programming homework samples at ProgrammingHomeworkHelp.com. From basic coding exercises to intricate algorithms in Java, Python, C++, and more, our samples exemplify proficiency and clarity. These examples demonstrate our commitment to delivering high-quality solutions tailored to academic needs. Dive into our samples to see how we can assist you in mastering programming concepts.