The objective of this mini-lab is to practice debugging code.
- The following function is supposed to return an image of a
flag. Without starting JES, read over the comments, as
well as the code. Circle as many errors as you can
find, and provide a correction for each. Label each error as either a syntax
error or a logic error.
#Draw the flag of Kazooistan.
# The flag is square with three colored regions:
# the upper left quadrant is black, the upper right quadrant is orange
# and the bottom half is white.
#Parameter: size -- the width and height of the flag.
#Returns: an image of the flag.
pic = makeEmptyPicture(size, size)
for x in range(size):
for y in rage(size):
pix = getPixel(pic, y, x)
# make the upper left black
if y <= (.5 * size) and x <= (.5 * size)
# make the upper right orange
if y <= (.5 * size) and y <= (.5 * size):
- Once you think you have found all of the errors in the above
code, copy it into JES and try to run it. Fix the syntax errors at
this point so that the code will actually load and run. You'll find
that the code doesn't do quite what it should. If you didn't see
the logic errors before, look over the code again to see if you can
figure out now why the code isn't working correctly.
- Fix the code so that the flag is generated correctly.
Print your results
- Print the corrected function and hand it
in, along with the version that you corrected by hand.