This homework assignment must be submitted in Gradescope by Noon central time on Tuesday March 5, 2024.
Collaboration is prohibited, and while working on this you should only consult the resources (books, online, etc.) listed below.
This assignment corresponds to Worksheet 8, covering topics:
set
and defaultdict
The materials you may refer to for this homework are:
This homework assignment has two problems. The grading breakdown is:
Points | Item |
---|---|
4 | Autograder syntax checks (problem 1) |
5 | Problem 2 |
5 | Problem 3 |
14 | Total |
Ask your instructor or TA a question by email, in office hours, or on discord.
Work in hwk8prob2.py
.
You will need to save the following PNG file in the directory where you do your work. All the links below take you to the same PNG file, so use whichever one makes it easiest for you to save it to a known location on your computer.
Link to the file: hwk8-campus-circle.png
Directory where you can find it on github: worksheets/images/
The image itself (which you may be able to right-click and "save as"):
This is an image of the UIC campus logo, a red circle with "UIC" written inside it in bold white sans-serif letters.
Write a Python program that uses Pillow (i.e. the PIL
module) to open this image file, analyze it, and print a report that answers these questions:
(255,255,255)
) and one other color (that we're asking for).Here's an example of what the output should look like, but using different colors and numbers than the actual answer:
UIC red is: (105,21,17)
Number of pixels of that color: 28055
Fraction of the area they account for: 38.5%
ALSO, please run your program and paste its output as a series of comment lines at the bottom of hwk8prob2.py
. That way we can see its output while reading the code during grading.
Work in hwk8prob3.py
. You'll need to import and use trees.py
, and I suggest you download a fresh copy because it has been updated include the methods you were asked to write in Worksheets 7 and 8. (You don't necessarily need to use those new methods, but their code may be a handy source of inspiration.)
Write a function save_tree_as_csv
that takes two arguments:
T
, a Node
or BST
object that is the root of a treefilename
, a string specifying the name of the desired output fileThis function should create a CSV file with two columns: location
and key
. After the header row, there should be one row for each node in the tree. In the row corresponding to a node, the value in column key
should be the key of the node, and the value in column location
should be a string containing only the letters L
and R
that, when read from left to right, indicates how to get to the node from the root (T
). For example, the string "LRL"
would mean: "To get to this node, start at the root, go to its Left child, then the Right child of that, then the Left child of that." The empty string ""
would be the location of the root node itself.
For example, the tree
- <True>
- / \
- <"Alice"> <False>
- / \
- <5.8> <5.5>
might generate a CSV file with the following contents:
location,key
,True
L,Alice
LL,5.8
LR,5.5
R,False
Use the following function definition line:
def save_tree_as_csv(T,filename):
Notes: