Handouts: Karel Reference
Worked Examples: Beeper Line
File: square_karel.py

Your goal is to place an outline of beepers in Karel's world, like below.


You can assume:

  • Karel starts on the bottom left of the world, facing east.
  • Karel's world is square (the same number of rows and columns), and is not 1x1

Your program should also work for worlds of different sizes (other than 1x1), like below:


Writing Code That Is Easy To Read

Decomposition. Remember, you can define functions with meaningful names and call those. Try looking at the Beeper Line worked example as a starting point when writing a helper function, and see what needs to be modified.

Using loops. Does your program use a for loop, like below?

for i in range(4):
    # your code here

If not, try it out! It will help you organize your code better. We promise :-)

Bonus Extension

Great job so far! There is one more topic, called if statements, that you will learn soon. Once you have learned that, you can optionally revisit this problem if you have extra time, and try to modify your program using everything you've learned, including if statements, to make Karel draw the following square, where all beepers in the square outline do not border any walls. This means that 1x1 and 2x2 worlds will not have any beepers in them. The world could also be any size, including non-square.

This part is purely optional.