Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

check_input.py def get_int(prompt): Repeatedly takes in and validates user's input to ensure that it is an integer. Args: prompt: string to display to the user

image text in transcribedimage text in transcribed

check_input.py def get_int(prompt): """Repeatedly takes in and validates user's input to ensure that it is an integer. Args: prompt: string to display to the user to prompt them to enter an input. Returns: The valid positive integer input. """ val = 0 valid = False while not valid: try: val = int(input(prompt)) valid = True except ValueError: print("Invalid input - should be an integer.") return val def get_positive_int(prompt): """Repeatedly takes in and validates user's input to ensure that it is a positive (>= 0) integer. Args: prompt: string to display to the user to prompt them to enter an input. Returns: The valid integer input. """ val = 0 valid = False while not valid: try: val = int(input(prompt)) if val >= 0: valid = True else: print("Invalid input - should not be negative.") except ValueError: print("Invalid input - should be an integer.") return val def get_int_range(prompt, low, high): """Repeatedly takes in and validates user's input to ensure that it is an integer within the specified range. Args: prompt: string to display to the user to prompt them to enter an input. low: lower bound of range (inclusive) high: upper bound of range (inclusive) Returns: The valid integer input within the specified range. """ val = 0 valid = False while not valid: try: val = int(input(prompt)) if val >= low and val  
maze.py *************** * * * *** ******* * * * * * * * * ** *** * * * * * * * * ***** * * * * * s* *f * ***************

CECS 277 - Lab 4 - File IO Maze Solver Create a program that allows the user to solve a maze that is read in from a file. The user will begin at the starting point ('s') of the maze and will be able to move up, down, left, or right to move through the maze. When the user reaches the finish (' f '), they have solved the maze. Create the following functions for your program: 1. read_maze () - read in the contents of the file and store the contents in a 2D list. Each character in the maze (make sure to keep all the spaces, but you can strip out the new lines if necessary) should be stored in a separate element in the 2D list (note: this function should work for any size maze, not just the 9x15 provided). Return the filled 2D list. 2. find_start (maze) - passes in the filled maze (of any size). Search through the elements in the maze using a set of nested for loops to find an ' s '. Return the location as a two item 1D list where the first item is the row, and the second item is the column. 3. display_maze(maze, loc) - passes in the filled maze (of any size) and the user's location. Iterate through the contents of the maze. Display each character in the maze in a matrix format. When you reach the user's location, display an ' X ' instead so that it shows where the user is in the maze (do not actually place the ' X ' in the 2D list, just display it). In the main function, you should have a loop with a menu that repeatedly prompts the user to move in a direction until the user finds the finish. The user will have a two item 1D list that stores the row and column of their location in the maze that is initialized to the start position of the map. Move the user by updating the row and column values in the location list by adding or subtracting 1 to the row or column (depending on the direction they moved). Do not allow the user to move through any walls ( \( \left({ }^{*} ' ight) \), check the maze at the location the user is moving to see if it is a wall, if it is, display a message that they cannot move there and do not update the user's location. Display the maze each time the user moves. When the user finds the finish, display a congratulatory message and end the program. Example Output: Notes: 1. Please place your name, date, and a brief description in a comment block at the top of your program. 2. Use the check_input module provided on Canvas to check the user's input for invalid values. Add the .py file to your project folder to use the functions. You may modify it as needed. Examples using the module is provided in a reference document on Canvas. 3. Do not create any extra functions or add any extra parameters. 4. Please do not create any global variables, instead, pass variables as arguments to the functions and return values back when needed. 5. Please read through the Coding Standards reference document on Canvas for guidelines on how to name your variables and to format your program. 6. Use docstrings to document each of your functions. Document all parameters and return values. Add brief comments in your program to describe sections of code. 7. Thoroughly test your program before submitting: a. Make sure that the file is read in correctly and each character is stored in a separate element in the 2D list. b. Make sure that you don't mix up the rows and columns of the 2D list. c. Make sure that your maze is displayed correctly (ie. properly oriented). d. Make sure that the user begins at the start position. e. Make sure that all user input is checked for invalid values. f. Make sure that the user correctly moves in the direction specified. g. Make sure that the user cannot move through walls in any direction. h. Make sure that the program ends when the user finds the finish

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

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

Write a Python program to check an input number is prime or not.

Answered: 1 week ago

Question

Write a program to check an input year is leap or not.

Answered: 1 week ago