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 Sunday the 3rd of March, at 11:55PM (5 min before midnight). You will need to upload a single python file via assignment submission link on Wattle.

NOTE: No excuses about technical problems like internet connection or computer issues are accepted. You can actually submit the homework as many times as you like, as the last submitted file will be marked. Do not wait until the last minute!

The homework is individual. You must write your own solution, and you are expected to be able to explain every aspect of it. 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. You may be contacted for an additional oral assessement, which may result in a change of mark.

If you have questions?

  • Ask the tutor in your lab,
  • Look at the Wattle discussion forum for similar question, and only post your question if not found,

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:

stack of three blocks

to this:

three blocks on the table

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. 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() and test_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.

In marking this assignment we will consider the following:

  • Did you put your name and uID at the top of your unstack.py?
  • Does your submitted file satisfy the requirements specified above?
  • Do the two test cases (test_unstack_two and test_unstack_three) work with your modified solution?

The assignment is worth 3% of your final mark.

bars search times arrow-up