Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

dufhadqlhylwzi xcqniythfkgwqw yozrfvkowgmvag lalvggzvmhgaha uluyopcpfgayeo ejemtipntmbeaw huqrhcumxtxcin vnrykbsftbgtag aofxxszwtktazk vgnitnuhtszzto lonthkmfkakpus dgznajtzalxgvs milyjorkjsgvtd hunting NOTE: Starting with this project, the itertools library in Python is

image text in transcribed image text in transcribedimage text in transcribedimage text in transcribed

dufhadqlhylwzi xcqniythfkgwqw yozrfvkowgmvag lalvggzvmhgaha uluyopcpfgayeo ejemtipntmbeaw huqrhcumxtxcin vnrykbsftbgtag aofxxszwtktazk vgnitnuhtszzto lonthkmfkakpus dgznajtzalxgvs milyjorkjsgvtd hunting NOTE: Starting with this project, the itertools library in Python is banned. 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 you've found) turned into periods. If you don't 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 don't have any requirement about how you store you data internally, I have some advice: the obvious data structure would be an array of strings. It's 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 we'll 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, that's 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 won't 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 don't need to error-check it.) You can also assume that the words are all made up entirely of lowercase alpha characters. While you're 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. Don't print anything out. 4 Your Output At the start of your program, print out a prompt. (To make it easier to auto- grade 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 doesn't exist, print out the following message: Sorry, the file doesn't 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 you've 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 it's 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, it's 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! 7 Example Code? Take a look at the .zip file I've provided. In addition to testcases, I've also provided a program that will generate new testcases. Not only is it a cool tool, it also might be useful to you, when you're trying to figure out how to write your own code! (Remember, it's never a violation of the Code if you are re-using or adapting something that I've provided you.) Unfortunately, since I wrote this code for myself - not for you, it's probably not commented as well as you would like. Guess you'll have to dig into it, to figure out how it works

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

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions