Spoilers below.A Gentle Introduction to the Art of Object-Oriented Programming If there is obstruction, program terminates. If there is indeed no obstruction, Karel will reposition itself to the first column and fill up a line of beepers. How it works: first fill a line of beepers, Karel will then check if there is not obstruction (walls) above it (using leftIsClear()). I'm currently working on a solution that doesn't involve the use of 'if', and I'll share it here if I can manage to get it working, no guarantees however.ĮDIT: I'm still unable to come up with a solution that doesn't involve 'if' statement, but below is my solution for this exercise (for those who want to progress to the next section). My belief is that because you hard-coded the number of times (for instance your use of repeat()) to fill the world row by row, and thus the program doesn't accept your answer because it only works for ONE specific world size. In other words, your code must be able to automatically fill in any world size (e.g. This is not made very clear in Lesson 5, but in Unit 8 Lesson 2, the comment in the code given says "no matter how big the world". I've been attempting the lessons as well, and after many attempts I finally managed to get past said problem, but I "cheated" a little by using an 'if' statement, which I'm pretty sure isn't covered yet (I just finished Unit 8). Can someone please explain this, and, ideally, help me think through this without giving me the answer? If, however, I proceed and run the rest of the code, the 8x8 gets satisfied, but the 5x5 is suddenly no longer valid. If I run function step1(), the code executes, and the requirements for the 5x5 world are satisfied. Here is my code: //Make Karel fill the world Working through the Stanford Karel lessons right now, and have got stumped on this one
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |