Github Classroom Link: https://classroom.github.com/a/yf7pux_8
This is a problem set of two problems, each of which has template files within which you will complete your work. Retrieve the assignment from the link below, download the ZIP (.zip) file, then extract all files. I would highly suggest then keeping the entire folder open in explorer/finder, to best edit the different files.
When you are finished, upload your completed templates back to Github, either via Github's "upload files" option or by using the "copy" and "paste" commands with Github's online file editor. Don’t change file names or add or remove files: overwrite the original template files.
Relevant files:
Relevant files:
You may wish to make note of the cases - all words are capitalized except the special "karel.py" Python file, which is lower-case.
We imagine Karel:
You do not need to use conditional 'if' statements or 'while' loops for this task, but you are welcome to do so.
You are not-quite-required to use more than one function (that is, more functions than just the required 'main' function) for this task. You are encouraged to use a function for at least two of the three steps.
My solution contained around 60 lines of Python (.py) including comments. I utilized the four functions provided in the template - main() and three optional functions. I used no 'if', 'while', or 'for' statements or loops. I expect using 'for' would reduced my lines-of-code by around 5, to around 50. My longest function was "return_to_start" at around 15 lines.
I did not successfully complete the task on my first attempt, confusing left and right in one case, and moving too many steps and colliding with a wall in another.
We imagine Karel:
The core learning objective of this problem requires you to write one Python (.py) file which may successful paint all four world (.w) files, despite differences in the "houses". You will need to use conditional 'if' statements or 'while' loops for this task, and are encouraged to use functions. My solution did not use a 'for' loop, but I thought there was one obviously place it could have.
There will always be at least two grid spaces between the "house" and the boundary of the grid.
There will always be an opening/door but it will not always be centered within the right/east wall.
My solution used four "while" loops, one for each of the three steps numbered above. For one of the tasks, I used one inner while loop placed inside an outer while loop. In every case, having each while loop contained within it's own function made the most sense to me, so in one case I had a function, which contained a while loop, which contained a function, which contained a while loop.
In my code, I see one clear place I could have used a 'for' loop instead of a while loop.
I used no 'if' statements.
Almost all of my movement and placement occurred within loops.
I did not successfully complete the task on my first attempt, as I did not realize Karel could start facing in any direction because I did not read the directions completely before testing my code. My code did work after fixing this single error, but I was quite surprised when it worked.
In addition to the notes on how I solved this problem, here are some hints provided by Prof. Jed Rembold, who designed this assignment. I used all three of these hints:
It may be non-obvious how to change world (.w) files. Here is an animated demonstration. Notice the slight delay between selecting files and the Karel window updating: