Question
python please~ 1 Overview Write a program named word_search.py . In this project, we will be implementing a word search. You will read your input
python please~
1 Overview
Write a program named word_search.py . In this project, we will be implementing a word search. You will read your input from a file: it will contain a grid of letters, a blank line, and then a set of words to find. You will search the grid for each word. If you find it, you will print out the grid again, but with all letters (except for the word youve found) turned into periods. If you dont find it, you will print a message to that effect. I will not tell you how large the grid is; you will have to figure that out from the file. I will guarantee that all of the lines in the grid will have the same number of characters, but I will not guarantee that the grid is a square; there it might be a tall or wide rectangle, sometimes.
2 How to Store Your Data
While I dont have any requirement about how you store you data internally, I have some advice: the obvious data structure would be an array of strings. Its easy, and works well! But as you write this program, I want you to be thinking ahead. An array of strings is basically the same thing as a 2-dimensional array. I want you to be getting ready for code, coming soon, where well be using 2D arrays, holding more complex data. Get experienced with indexing into the array, and build your comfortability using nested for loops to read, print, or modify a simple data structure. Note that, for the sake of printing out the grid when you find, you may find it handy to duplicate the grid into an actual 2D array; that is probably a good way to do it. However, you are not required to do it that way; if you come up with another solution, thats OK too.
3 File Format
The input file will have a series of lines, with no blank lines or comments. Each one will be made up only of lowercase alphabetical characters - there wont be any whitspace, numerals, or other strange characters to worry about. After the grid, there will be a single blank line. After the blank line, you should read each additional word from the file; there will only be one word per line. (You can assume that, you dont need to error-check it.) You can also assume that the words are all made up entirely of lowercase alpha characters. While youre in the words to search for part of the file, you should ignore any line that is blank, or that is made up entirely of whitespace. Dont print anything out.
4 Your Output
At the start of your program, print out a prompt. (To make it easier to autograde on GradeScope, please print this on its own line with print(). Then call input(), with no parameter, on the next line.) Please give the puzzle filename: If the file doesnt exist, print out the following message: Sorry, the file doesnt exist or cannot be opened. and terminate the program. Otherwise, open the file, and read its contents. While we will test you on checking to see if the file exists, we will not test you on invalid file contents. If the file exists, you may assume that it is valid. For each word that you search for, either print the grid out (with everything except the word that youve found replaced by periods), or print the message Word word_here not found. In either case, print a blank line after you print out the search result.
5 Directions
It will be very easy to search for the word going left-to-right! And its not a lot harder to search right-to-left. Searching up-down is a little trickier, and searching diagonally is harder still. You will be required to find words going in all 8 directions. However, you can earn most of the points without having to search in the northwest and southwest directions. We will test those - but only in a few of the testcases.
6 Hints To search diagonally, the best algorithm I know is to actually use a while loop. Think about it this way: imagine that you were a tiny little person, walking on the grid. Where could you start your walk, and what directions could you go? What direction would you move, each time that you took a step? If you get tricky, its actually possible to have all 8 directions use the same basic search algorithm: you simply have 8 different directions to search from, for each given point. See if you can find a common way to solve them all!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started