Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with a python program. All the instructions are going to be provided in order to be able to do this program. Note:

I need help with a python program. All the instructions are going to be provided in order to be able to do this program. Note: It is important to mention that we have just covered while loop, for loop, lists and dictionaries; in other words, we haven't covered any advanced python syntax stuff). So, here are the instructions:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
\fCSc 1 10 WordSearch In this assignment, you will be tasked with writing a program that nds certain words within a wordsearch grid and prints out the word mapped to the line and starting character location of each word. The information of the board, and the words will be provided by the user via les you will need to read in. The user will also need to specify the direction of the words: Horizontal or Vertical. You should name the le _. Program Behavior L B A C K W A R I bezoczb This program should accept three inputs from the user. The rst input is the name of the le containing the words you will be looking for [See section on wordstxt). The second input is the name of the le containing the wordsearch board (See section on puzzletxt). The third input will be the direction you will be looking in Horizontal or Vertical. wordstxt Your program should open up and read 0 le names words.txt. You can assume that this le already exists in the same directory as wordsearchpy. When testing on your computer, you should create your own -. Using this information, you can determine which words you are searching for in your punle le! You can assume that each line of is formatted as follows: forward_word:backward_word In other words, the rst word on a line of the le is a word from the "word bank". A colon separates that word from the backwards version of that same word. For instance: computer:retupmoc science:ecneics Your program should open and read the- le into the program and store the mapping between forwards and backwards words in a dictionary. The keys of the dictionary should be the forward version of the word, and the value the keys map to, should be the backward version of that word. Given the example content of shown above, the words dictionary should have the keys and values shown below: words = { "com put er" : " retupmoc " , "science" : "ecneics" , After you have read in the le and constructed this dictionary, you can use it to determine your word bank, which words you will need to look for within the -. puzzledxt This le contains a grid of letters and hidden within those letters are certain words you will need to be searching for. You will use your newly created words dictionary to gure out what letter combination of words you need to nd. This is an example of what this word-grid le would look like: NUDIHSMZH MRMEHANDA LZHINOKLH SREGNEVAV IFRCXHCQX AHTZBAYKQ ARAMERICA The puzzle le could have more or less Rowleolumns depending on each test case. Output The program should print out the starting row 1 col locations for each word found. The formatting of the outut should be something like: wordl found at [r'owlJ coll] wordZ found at [row21 c012] It should print out the words in the order found. In horizontal mode. this means printing out the words found in the rows from top to bottom. In vertical mode, this means printing out the words found in the columns left to right. Example Run Say that contains: army : ymra navy : yvan star : rats emerica : acirema bullet : tellub and then contains: Z S Y M R A Z R N Z Z A Q L M A T R T U I N V Y A S S D B Y Z T C V B V B U L L E T A M E R I C A Then the inputs and [horizontal mode) should give these results: army found at [1, 6] bullet found at [6, 2] america found at [7, 1] The inputs - and (vertical mode) should print this instead: navy found at [2, 2] star found at [4, 5] Development Strategy This section covers how you should go about structuring and implementing the code. In total, your program should have at least 5 functions. My recommendation for these ve functions: - A main function . A function to load in the fonNards I backwards words and save into a dictionary . One for searching through horizontal lines - One for searching through vertical lines . One for checking if a word is found on a line You may have other functions as well. You should build this program in the following sequence: (1) Create a main function In this step. create the main function. and plan to call some of your other functions from main. The main function should ask the user for the three inputs, call a function to load in the contents of the dictionary file, determine the mode, and then call the correct function for handling the wordsearch depending on the selected mode. (2) Reading in wordstxt Create a function that will be responsible for opening up the words le and reading in the information. Main should have already asked the user for the name of the le. You can pass the le name into this function via arguments} parameters. The function should iterate through the lines and create a dictionary that maps the forwards-spelling to the backwards spelling. After the data is read in, the function should return the dictionary back to main. (3) Input le Next, add the code to ask the user for the input word grid le and open it up. This could iust go right in main, or in a separate function that returns the le to main. (4) Horizontal Mode Horizontal mode is a bit easier than vertical mode, so I recommend that you work on this rst. Create a function for this, and pass it the word dictionary, the grid le, and the mode. Iterate through the lines of the le one-at-a-time. For each line you encounter, you can search for all of the words in the word dictionary to see if you can nd it. If you try to do all of this in one function, you will probably end up with 3 or 4 levels of nested loops, which can get rather disorganized. I recommend that you create another function, perhaps called something like that handles processing one line of searching. The horizontal function can call this for each line that it encounters. There will be separate test cases for horizontal and for vertical. I recommend that you get the horizontal ones to pass before oving on to vertical. (5) Vertical Mode In vertical mode, you have to search for the words in the columns of the grid, rather than the rows. This is a bit more complex, but still very do-a ble. The way you should go about this is create a loop where you iterate through the column indexes. Within this loop, create another loop that goes through every character in that column and creates a list of those characters. Then, you can treat this column as if it is a row, and pass it into the_ function that you wrote in the last step. Rules, Comments, Style You should follow the style rules described in the class style guide. Also. you are requred to use a dictionary for the forwards} backwards word component of this PA. If you have any questions about style, comments, formatting, etc please ask

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions