This is the first homework assignment. Your goal in this assignment is to read and understand a simple program, and modify it so that it works. Along the way, it is also important that you get familiar with the python programming environment, and take your first step towards learning how to use it effectively.
Practical information#
The assignment is due on Monday the 8th of August, at 9am. To submit your solution, you will upload a single python file via Wattle. Here is the assignment submission link.
In addition to submitting your solution, you must attend the lab in week 3. In the lab, you will have to discuss some questions about the assignment. Your tutor will also ask you some questions about your solution, and give you feedback if there is anything you need to improve. This discussion is part of the assessment. If you fail to show up for the discussion, you will receive zero marks for this assignment. If you do not submit a solution, you may still get partial marks for the in-lab discussion.
The homework is individual. You must write your own solution, and you are expected to be able to explain every aspect of it. Also remember that you are not allowed to share your solution (code) with other students; this includes posting it (or parts of it) to the discussion forum, or to any other on-line forum.
If you have followed the lectures and worked through the exercises in lab 1, the assignment should not take more than one to two hours to complete.
The problem#
This assignment problem uses the robot simulator that was introduced in Lecture 2, and also used in lab 1. First, you must download these two files:
Save both files to the same directory.
The problem is how to unstack a tower of blocks. That is, to go from this:
to this:
The colours of the blocks are not important: After unstacking, the blocks should be ordered left-to-right in the same order that they were top-to-bottom in the tower, no matter what their colours are. The final position of the robot also does not matter.
unstack.py
contains several functions that implement a solution to
this problem. Because the robot (at least in simulation) can carry more
than one block, the idea of the solution is that we will first unstack
the top two blocks from the third, put down this stack of two, and then
solve the smaller problem of unstacking the top block from the stack of
two using the same manoeuvre.
However, the implementation of this solution has some errors. Your task
is to correct the errors.
unstack.py
also contains two test functions, called test_unstack_two()
and test_unstack_three()
. The first tests the simpler case of unstacking
just two blocks, while the second tests unstacking of a tower of three.
Because the file contains only function definitions, you will not see anything happen when you run it. To run the test functions, you must first run the file and then call the function, for example
In [1]: test_unstack_two()
The first error you will encounter is a NameError
. As mentioned in
the lecture, this means there is a mismatch between the name of a
function’s definition and use. Use the information from the python
error message to track down where the error is.
Once you have resolved this error, the test_unstack_two()
function
should work. In the solution for unstacking three blocks there is a
logical error that may require more thought to fix. However, it does
not require a big change to the functions. You should not write an
entirely new program. Focus on understanding how the given program is
intended to work, and what changes are needed to make it work.
(It may be as simple as changing one line.)
Marking#
What to submit
You should edit the file unstack.py
that you downloaded, then upload
only this file with your corrections using the
assignment submission link
on wattle. Do not edit (and do not try to upload) robot.py
.
The file that you submit must meet the following requirements:
- It must be syntatically correct python code.
- Like the file you downloaded, your solution should be implemented
in functions; anything outside of function definitions in the
file will be ignored. The file must of course include the
import
statement, and you can (and should!) use comments. - The two functions
test_unstack_two()
andtest_unstack_three()
must not be modified (that is, they should be exactly the same as in the file you downloaded). We will test if you have solved the problem using the same testing procedure that is described by these two functions.
As mentioned above, you must also attend the lab (in week 3) and discuss your solution. This discussion is part of the assessment. You should be prepared to answer or demonstrate to the following questions:
- Can you download the file that you submitted from wattle?
- Can you run that file in the python interpreter using an IDE of your choice?
- If the file has syntax errors, can you use the error messages from the interpreter or IDE to identify where the syntax errors are?
- Does your submitted file meet the requirements stated above? Does
it contain anything that is not a function definition, an
import
statement, or a comment? If so, can you point it out? - What was the cause of the
NameError
in the original file, and how did you fix it? - How did you fix the logical error in the
unstack_tower_of_three
function? Was this the smallest change necessary to fix the error? - The original file had comments describing the each function, and the assumptions about the state of the robot when the function is called. Are these comments still accurate in your version? Have you modified the comments so they correctly describe the functions that you modifed?
In marking this assignment we will consider the following:
- Does your submitted file satisfy the requirements specified above?
- Do the two test cases (
test_unstack_two
andtest_unstack_three
) work with your modified solution? - Your ability to use the tools (e.g., the IDE or python interpreter), your understanding of python’s error messages, and your understanding of the solution, as demonstrated in your discussion.
The assignment is worth 2% of your final mark.