$ mkdir ~/cs170/labs/lab31 $ cd ~/cs170/labs/lab31
It's that time of year again! Time for you to fill out course evaluations. The college really likes to have a high response rate to course evaluations. And since my response rates are usually pretty low I figured I should probabaly do something to change that.
Some things to keep in mind:
I'm going to give you guys some class time to work on them. I'll sit out in the lounge for about 10 - 15 minutes to give everyone an opportunity to fill them out. I'll send someone in to check and see how things are progressing, and I'll come back once everyone is done.
In addition to the written portion of the test, there will be a coding portion. This will be done on the computers. For practice, attempt the following exercises in a file called test_review.py, alone. Make sure you follow all coding conventions, including!
Download the file linked_list.py,
which contains a
LinkedList class. Add a method called
slice(self, start_index, end_index), which returns a
new linked list containing only the elements from the current list
between the two indicies specified (including start_index, excluding
end_index). Read the provided code carefully for this exercise.
>>> linked_list = Linked_List() >>> for i in range(0, 11): ... linked_list.append(i) >>> new_linked_list = linked_list.slice(2, 4) >>> print(linked_list) head -> 10 -> 9 -> 8 -> 7 -> 6 -> 5 -> 4 -> 3 -> 2 -> 1 -> 0 -> None >>> print(new_linked_list) head -> 8 -> 7 -> None >>> new_linked_list = linked_list.slice(1, 8) >>> print(linked_list) head -> 10 -> 9 -> 8 -> 7 -> 6 -> 5 -> 4 -> 3 -> 2 -> 1 -> 0 -> None >>> print(new_linked_list) head -> 9 -> 8 -> 7 -> 6 -> 5 -> 4 -> 3 -> None
Download the file tree.py, which
BinaryTree class. Add a method called
double_nodes(root), which inserts a duplicate of each
node as their own left child. This just adds an additional node in
the left tree of each node, as each newly created node will only
have a left child.
>>> my_tree = BinaryTree() >>> my_tree.insert(5) >>> my_tree.insert(3) >>> my_tree.insert(8) >>> my_tree.insert(4) >>> my_tree.insert(6) >>> my_tree.insert(7) >>> print(my_tree.pre_order()) 5 3 4 8 6 7 >>> my_tree.double_nodes(my_tree.root) >>> print(my_tree.pre_order()) 5 5 3 3 4 4 8 8 6 6 7 7
Write a function called
which takes as a parameter a string. This function should recursively
compute all of the anagrams of the input word. They do not need to
be real words. You may need to write a helper function for this problem.
>>> print(compute_anagrams("bob")) ['bob', 'bbo', 'obb', 'obb', 'bbo', 'bob'] >>> print(compute_anagrams("cpsc")) ['cpsc', 'cpcs', 'cspc', 'cscp', 'ccps', 'ccsp', 'pcsc', 'pccs', 'pscc', 'pscc', 'pccs', 'pcsc', 'scpc', 'sccp', 'spcc', 'spcc', 'sccp', 'scpc', 'ccps', 'ccsp', 'cpcs', 'cpsc', 'cscp', 'cspc']
When you have finished, create a tar file of your
lab31 directory. To create a tar
file, execute the following commands:
cd ~/cs170/labs tar czvf lab31.tgz lab31/
To submit your activity, go
to inquire.roanoke.edu. You
should see an available assignment called
31. Make sure you include a header
listing the authors of the file.