Python代写:CSCA08 Word Search调试Python

Python,Word Search Puzzle.

Introduction

The goal of this assignment is to get you started reading and writing Python code. You’ll understand how to use existing code, call existing functions, write your own functions, and call functions you’ve written. This work is not harder than what you’ve been doing in your exercises, but it will take substantially longer, so start early. Make sure you read this entire document all the way through at least once before you start.

What Not to Use

You can complete this assignment using only the material covered in the first three weeks of the course. In particular, you are not allowed to use any if-statements (there is no good reason to use them in this assignment!), and do not use string methods.

A word search puzzle is a rectangular grid of letters that contains hidden words. In the word searches we use here, words can be hidden in one of four directions:

  • left-to-right (horizontal forwards)
  • right-to-left (horizontal backwards)
  • top-to-bottom (vertical starting from the top)
  • bottom-to-top (vertical starting from the bottom)

The first two of these directions are in the horizontal dimension, and the second two are in the vertical dimension.

Download and open a1.py. It is a Python file in which you will solve 12 tasks related to word searches. Not all tasks will be marked, but later tasks build on earlier ones. You are strongly encouraged to complete all tasks - you’ll thank me later!

Starter Code

At the top of the file are some comments. Please read those comments now, and complete the header… go on… I’ll wait here.

Next, you see a variable assignment to PUZZLE1. PUZZLE1 is a word search with nine rows and nine columns in which the following words are hidden:

  • marzieh (2 instances)
  • brian (2 instances)
  • nick (2 instances)
  • eric (1 instance1)

Before continuing, find all of the words in the puzzle by hand. Remember that they can be in any of four directions. Here’s a hint for finding the brians: one instance is right-to-left , the other is bottom-to-top. Below PUZZLE1 is PUZZLE2. It’s a bigger puzzle with the same words hidden in it, but we’re not telling you the number of instances of each word that are in there. We’ll come back to this puzzle later. Below PUZZLE2, we have given you two starter functions that you will use in completing some of the tasks. These functions use Python concepts that we haven’t covered yet, so don’t concern yourselves with the implementations. (If you are interested, the code is well-commented, so that by reading the comments you should get an idea of what’s happening.) Instead, to learn what the functions do, read the docstrings and experiment in the shell. The two functions are as follows:

rotate puzzle 

As indicated by the docstring, this function rotates a puzzle by 90 degrees to the left. … What exactly does that mean? To get an idea of what the function does, run a1.py and call rotate puzzle from the shell. For example, try rotate puzzle(PUZZLE1). Observe the effect. Try it on smaller “puzzles” too, like this: rotate puzzle(‘abc\ndef’). Do you understand what the function is doing? (The \n there is just the code for a newline character.

lr occurrences 

This function takes a puzzle and a word, and returns the number of times the word occurs in the left-to- right direction in the puzzle. Play around with this function before continuing. You know the number of occurrences of each word in PUZZLE1; use this function to verify the number of left-to-right occurrences of these words. Try it on PUZZLE2 as well!2

On line 103 of a1.py is a comment indicating that your code should be below. You are not allowed to modify anything above this line, except for the header. Below this point, there are 12 tasks to complete. Be careful: they are not listed in the code in numerical order. Make sure you work on the tasks in order of number, not the order that they occur in the code.

Your Tasks

Here are your tasks for the word searches. Read the tasks below carefully, and follow along with the code so that you know where to add code and what to add. Part of the goal of this assignment is to give you practice following instructions exactly. What might be considered small mistakes in other disciplines can be surprisingly important in programming. For example, if you print something when you were supposed to return it, it is wrong. If you build a string in a different format than what is expected, it is wrong.

  • Task 1: this task comprises four subtasks. All four are very similar, and are found in the do tasks function.
    • Task 1a: you are adding a print function call that prints the number of times name occurs in the left-to-right direction in puzzle. Mind the hint in the code!
    • Task 1b, 1c, 1d: for each of these tasks, you want to print in the same format as task 1a. That is, each of these tasks will have two calls to print. Rotating puzzles is going to be extremely useful here. What happens to words and their directions when you rotate the puzzle?
    • This is a good time to run a1.py and observe the output. Notice that there is a call to do tasks right below the indented body of the do tasks function. The function call passes PUZZLE1 and ‘brian’ as arguments to do tasks. Your code is working correctly if it runs with no errors and outputs the expected results for all four directions. If you get errors, or the output is wrong, go back over tasks 1a-d and debug your code.
  • Task 2: For this task, you are calling do tasks again. Heed the advice given in the comments! (Make sure you run your code frequently to make sure you haven’t accidentally broken anything.)
  • Task 3: now you get to write your own function. Carefully read the docstring for total occurrences to figure out what to do. What are you supposed to calculate? Are you returning it or printing it? What do the parameters mean? What does the example and type contract tell you? Make sure you are clear on these before writing the code! Also, think back to earlier tasks you have done and how they might help you write this function. Once you have written the code, test the function by calling it from the shell. It’s best to know now if there are problems before you start to rely on this function. Test it on small puzzles that you create by-hand. They don’t have to be real puzzles; small examples are often most useful for isolating bugs. Test on words that do not exist in the puzzle, words that exist once, and words that exist more than once. Then, test on PUZZLE1 and PUZZLE2 - your function should work on any puzzle.
  • Task 4: here you call the total occurrences function that you just wrote. Run the program after this step to make sure your function call is working.
  • Task 5: another function to write! Except this time, you have to write everything: example, description, type contract, and body (code). The in puzzle horizontal function should return True iff the given word can be found in puzzle in one or both horizontal directions. So if you find the word going left-to- right, or find it going right-to-left (or both), return True, otherwise return False. As in task 3, test the function from the shell on small puzzles before moving on.
  • Task 6: add a call of the in puzzle horizontal function you just wrote in task 5. As usual, run the program and compare the output to what is expected!
  • Task 7: Now run your tasks on PUZZLE2 (the big puzzle). Observe the output. Make sure it is correct before continuing!
  • Task 8: the in puzzle vertical function should return True iff the given word can be found in puzzle in one or both vertical directions. So if you find the word going top-to-bottom, or find it going bottom- to-top (or both), return True, otherwise return False. Keep using the function design recipe! You’re not being asked to add a call of this function to your code, but you should definitely call the function a few times with different parameters to make sure it is working correctly!
  • Task 9: the in puzzle function should return True iff the given word can be found anywhere in puzzle. So if you find the word in at least one of the four directions, you return True, otherwise you return False. Think carefully of how you can use existing functions to make this function a lot simpler!
  • Task 10: the in exactly one dimension function should return True iff the given word can be found in puzzle in exactly one of the two dimensions (horizontal or vertical), but not both. So if you find the word horizontally (left-to-right or right-to-left) or you find it vertically (top-to-bottom or bottom- to-top), and assuming you don’t find it both horizontally and vertically, then return True, otherwise return False. Again, think about what earlier functions can make this task easier? This is a question you should always be asking when you write a new function. (Be careful with your booleans on this one!)
  • Task 11: the all horizontal function should return True iff all occurrences of the supplied word are horizontal in the puzzle. (If word is not in the puzzle at all, then True is to be returned.)
  • Task 12: the at most one vertical function should return True iff word occurs at most once in the puzzle and that occurrence (if present) is vertical.

Type Checker

We have included a file called typechecker.py that runs each of your functions and checks that the type of the return value is correct. Again, you don’t have to understand this code (I wouldn’t expect you to at this stage), you just have to put it in the same directory as your a1.py file and run it.

This file serves 2 purposes, first it calls your functions, so you can be sure that they are named correctly (if they aren’t it will crash. Secondly it checks the type (not the value, just the type) of each function’s return, so you know if you’ve at least got that part right. If there is anything wrong, you will see an error message. If the types are correct, nothing will happen, except a single print statement.

This doesn’t mean that your function works (for example, replacing any of the boolean functions with just the line return True will still pass the type checker, but it’s a good first test. You will still want to test your code further.

Marking

Your assignment will be marked for correctness. This means that your code must do exactly what is described in this handout and starter code. In addition, we strongly encourage you to consider the following criteria as you work on this assignment - paying attention to these will help you as we progress through the course!

  • Formatting style: Make sure that you follow PEP-8 style guidelines that we have introduced.
  • Programming style: Your variable names should be meaningful and your code as simple and clear as possible.
  • Commenting: be sure to include accurate and complete docstrings in your functions. Follow the design recipe we have been using! In addition, include internal comments for pieces of code that aren’t trivial.
  • Code re-use: you should have as little duplicated code as possible. If you find yourself repeating code, there’s a good chance you could find a simpler (lazier) method.
  • One more time… this will be marked by an auto-marker. So if your file or one of your functions is named incorrectly, you won’t get any marks for that component of your work.

What to Submit

Submit a1.py and a1.test on MarkUs. Your file must be named exactly as given here (check that MarkUs says you have submitted all required files after you’re done submitting). You do not need to submit typechecker.py.

Before you submit:

  • Ensure that you have read amp; added your name and login to the header at the top of the file - Test your code for PEP-8 compliance
  • Run the type checker and make sure it gives no errors
  • Re-test all examples

Happy Searching!

热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图