Submitting
Regardless of how you choose to complete the assignment, you MUST submit the file you worked on to Canvas. Starting this week you can complete the assignment by: 1. Doing it on your own and submitting it to be graded; 2. Coming to class on Wednesday and working on it in your tutorial team; 3. attending one of our alternate tutorial times (see OH schedule - the second tab that says “Alternate Tutorial Times”).
IF YOU ARE SUBMITTING REMOTELY
If you’re submitting remotely, your submitted file will be graded for completeness and correctness via an autograder. Make sure your functions are named as the assignment specifies exactly.
IF YOU ARE IN CLASS OR AT AN ALT TUTORIAL
Remember the Alternative Tutorial Schedule (these are hosted throughout the day on Tuesday and Wednesdays) is available on the Office Hours Spreadsheet on the tab labeled “Alternative Tutorials.”
Then your file will be graded for participation (i.e. it’s okay if you haven’t finished the entire thing because you may have spent time asking a question; helping a friend; etc.) along with what we call a ‘peer review.’ Find one other person in your group that is finished and peer review each other’s work. Here are the things to check:
- Does their code look readable and neat?
- Can you understand what their code does by reading it?
- How was their solution different from yours (if at all)?
- Does their program run and generate the correct results?
Once you’ve debriefed, both of you should fill out this attendance Google Form. NOTE: You will need the NetID of the person's whose code you reviewed. This form will only be available near the end of the tutorial session.
Intro
LEARNING OBJECTIVES:
- Practice writing your own reporters
- Practice using reporters and making compound shapes
In this tutorial, we’re going to A. practice using sequences and writing reporters; B. make more compound shapes like you did in Exercise 2.
First, download the starter template and move it into your cs110
folder.
Then grab this
Do I need to import these functions?
Normally, in order to use functions from an external module, we have to specifically import the functions we wish to use:Part 1. Reporter Practice
Let’s get some practice with sequences of data and with writing some reporters! First, locate the part of your template that says:
## Reporter and Sequence Practice goes here
Activity 1.1.
First create a
- Your favorite number (
int ) (position0
) - Your favorite color (
string ) (position1
) - Your favorite TV show (
string ) (position …) - The department code of your favorite class at NU so far (e.g. COMP_SCI, HIST, MATH, etc.) (
string ) - The class number of your favorite class at NU so far (e.g.
110
,211
, etc.) (int ) - A list that contains all of the courses you’re taking this quarter (e.g.
["COMP_SCI 110", "HIST 202", "ECON 304"] ) (list ofstring s)
For example, here’s what mine would look like (go ahead and copy my fave things into your program in addition to yours (
bains_favorite_things = [13, "green", "The West Wing",
"COMP_SCI", 111,
["COMP_SCI 110", "COMP_SCI 396",
"COMP_SCI 399"]]
Activity 1.2.
Now write a function called get_favorite_color
that takes as its only parameter a list of someone’s favorite things and returns their favorite color. You can test your function by running the following program:
my_fave_color = get_favorite_color(my_favorite_things)
print("My favorite color is: " + my_fave_color)
bains_fave_color = get_favorite_color(bains_favorite_things)
print("Dr. Bain's favorite color is: " + bains_fave_color)
You should see both your favorite color printed AND my favorite color printed and you should NOT see
Hints!
- Remember we can access specific elements of a list with the syntax
name_of_sequence[index] where the name_of_sequence is just the variable name that stores said sequence and index - Remember that function headers only specify the function's name, its parameter names, and which parameters are optional. If we want an parameter to be a list...we don't do anything in the function header. We simply give it a reasonable name (e.g.
my-cool-list ) and treat that variable as if it's a list inside the function's body. When we call the function, we carefully make sure that function receives a list as an argument. - In this case, your function header will be very simple:
def get_favorite_color(someones_favorite_things): . - On each line of your function's body, try to limit yourself to one single action. In this function, we basically need to do two things: 1. access JUST the person's favorite color from
someones_favorite_things and store it in a variable of our choosing; 2. return that variable.
Solution
# Here we define our function
def get_favorite_color(someones_favorite_things):
# Notice we use the parameter name (someones_favorite_things)
# so that this function will work with ANY given list of favorite things
just_fave_color = someones_favorite_things[1]
return just_fave_color
# Now we have to call our function.
# First we call it with your favorite stuff
my_fave_color = get_favorite_color(my_favorite_things)
print("My favorite color is: " + my_fave_color)
# If you see "None" printed, it's a good sign that you've forgotten to make your
# function a reporter
# Next we call it with my favorite stuff to make sure it works with different
# people's favorite stuff.
bains_fave_color = get_favorite_color(bains_favorite_things)
print("Dr. Bain's favorite color is: " + bains_fave_color)
Activity 1.3.
Now write a function called multiply_favorite_numbers
that takes in two parameters, which are two favorite things lists like the above, and returns the product of the two favorite numbers. For instance, if you ran it like below:
print("The product of our fave numbers is...")
print(multiply_favorite_numbers(my_favorite_things, bains_favorite_things))
You’d see whatever the result of multiplying 13 (my favorite number) by your favorite number is.
Hints!
- Here we need TWO parameters for our function, both of which are lists. Maybe name them
fave_things_1 andfave_things_2 . - Remember try to write your function's body in a series of steps. 1. Extract the favorite number from
fave_things_1 and store it in a variable; 2. Extract the favorite number fromfave_things_2 and store it in a variable; 3. Multiply those two variables together and store it in a variable calledresult ; 4. Return the calculated result.
Activity 1.4.
Finally, write a function called
print("Rando class: " + rando_class(my_favorite_things))
print("Rando class: " + rando_class(my_favorite_things))
print("Rando class: " + rando_class(my_favorite_things))
Can't remember how to use the random module?
- First you'll need to import the appropriate function near the top of your program using the import syntax:
from module_name import function_name - The module we want to use is called
random - The function that randomly selects an element from a list is called
choice -
choice is a reporter that takes a sequence as input and returns a randomly chosen element from the list. - So for instance,
choice([1, 2, 3, 4]) would return a random element from the list[1, 2, 3, 4] . You could of course replace that list with any sequence or variable that contains a sequence.
Did you get the same course every time?
- Any chance you did something like:
return choice(list_name[-1]) ? - If so, you're on the right track...but Python is a peculiar language. It's trying to be helpful but is instead doing something we can't actually see.
- Instead of this approach try separating out the random choice and return steps.
- So first...
chance = choice(list_name) - And then
return chance
Part 2. Shape Shenanigans
Alright, time to have some fun with art. In last week’s HW Exercise you only had access to an oval
function. Then on Friday in-class, we introduced the rectangle
function. Today, WE UNLEASH THE TRUE POWER OF SHAPES. Here, you have access to all of the functions described in the below link:
Pay very close attention to the type of parameters each one requires. They’re different than our functions from last week! YOU DO NOT NEED TO DEFINE ANY OF THESE FUNCTIONS. They are defined for you and you simply need to call them. Unless an activity says, “write a function…” you do not need to write a function.
Activity 2.1
Spend a few minutes calling some of these functions. If you were super comfortable with oval, circle, rectangle, and square, skip straight to triangle, polygon, and line. Make sure to experiment with different arguments to get a sense of what sorts of shapes each function can make. Tag team with your team mates and try unique arguments. If you’re completing the tutorial remotely, you need to create at least 4 unique shapes. Since these are reporter functions, store them in variables shape_1
, shape_2
, shape_3
, and shape_4
.
Want some cooler colors to work with?

Activity 2.2
Now, in Exercise 2 (and in Part 2 of this tutorial), we used a bit of math to draw shapes on top of each other. However, we could also use some layout functions to do the same thing! All the shape functions are reporters meaning they return the shape they create back to us. That means we could store that shape in a variable or use it as an input to another function! In addition to those shape functions we explored in the prior task, this file also has access to a bunch of layout functions which are also described in the documentation linked above:
-
overlay -
underlay -
above -
below -
beside -
duplicate -
rotate
Try out each of these functions with some of the shapes. Here’s an example:
# First make a circle like we did last week
circle1 = circle(center=(200, 200), radius=50, color=bains_favorite_things[1])
# Now make a square...but notice we don't need to specify a center!
a_square = square(size=25, color="blue")
# Now rotate the square to make it more like a diamond
a_square = rotate(a_square, degrees=45)
# Finally use overlay to position the diamond ON TOP of the circle
overlay(a_square, circle1)
# notice, in this example we didn't have to ever think about the location of any shape
# other than the first one we drew!
If you’re completing the assignment remotely, make at least two compound shapes (e.g. a compound shape is a shape consisting of at least 2 basic shapes along with at least 2 manipulations from the above list).
Activity 2.3
Now we’re going to make a compound shape using these new techniques – namely the flag of the Chicago.
Note: Want to make a different flag? Go for it!
You’ll need, at minimum, to use
Flag of Chicago Screenshot

It doesn’t need to be EXACTLY like the above, but it should be as close as you can get it.
If you have extra time, get started on Exercise 3.