Assignment 2 - Drawing Shapes
Due: Thursday, September 25, 2025, at 10pm
You may work alone or with a partner, but you must type up the code yourself. You may also discuss the assignment at a high level with other students. You should list any student with whom you discussed each part, and the manner of discussion (high-level, partner, etc.) in a comment at the top of each file. You should only have one partner for an entire assignment.
You should submit your assignment on Gradescope. See below for which files to submit.
Getting started:
Both parts of this assignment will require you to use the graphics.py library. You should download a copy from here and save it in the same folder as your assignment code.
Goals
The primary goal for this assignment is to give you practice working with the graphics.py library. You will additionally get practice writing loops, working with objects, and working on bigger programs.
Parts of this assignment:
- Part 0: Quantitative Literacy Reasoning Assessment
- Part 1: Making a picture
- Part 2: Placing checkers pieces
- Part 3: The
randomlibrary - Part 4: Randomly placing checkers pieces
- Reflection
Comments and collaboration
# You should be equipped to complete this part right away.
As with all assignments in this course, for each file in this assignment, you are expected to provide top-level comments (lines that start with # at the top of the file) with your name and a collaboration statement. For this assignment, you have multiple programs; each needs a similar prelude.
You need a collaboration statement, even if just to say that you worked alone.
Here is an example of how you can start a file:
# File: picture.py
# Purpose: Draws shapes based on user clicks.
# Author: Lulu Amert
#
# Collaboration statement:
# - Milo: partner (worked on code together)
# - Hobbes: discussed how to use a mouse click
# - Mal (Course Staff): how to make a CircleHere is another example:
# File: randomPieces.py
# Purpose: Draws one checkers piece per row in a random column.
# Author: Hobbes Amert
#
# Collaboration statement: I worked alone.
#
# Inputs:
# * n: size of grid (int)Note on style:
The following style guidelines are expected moving forward, and will typically constitute 5–10 points of each assignment (out of 100 points).
- Variable names should be clear and easy to understand, should not start with a capital letter, and should only be a single letter when appropriate (usually for
i,j, andkas indices, potentially forxandyas coordinates, and maybepas a point,cfor a circle,rfor a rectangle, etc.). - It’s good to use empty lines to break code into logical chunks.
- Comments should be used for anything complex, and typically for chunks of 3–5 lines of code, but not every line.
- Don’t leave extra print statements in the code, even if you left them commented out.
- Make sure not to have code that computes the right answer by doing extra work (e.g., leaving a computation in a for loop when it could have occurred after the for loop, only once).
Note: The example triangle-drawing program on pages 108–109 of the textbook demonstrates a great use of empty lines and comments, and has very clear variable names. It is a good model to follow for style.
Part 0: Quantitative Literacy Reasoning Assessment
# You should be equipped to complete this part right away.
This part of the assignment is due earlier, on Monday, September 22nd at 10pm.
As this course satisfies the QRE requirement and in partnership with the Quantitative Resource Center, we are participating in a pilot of a quantitative assessment. You are not graded on your score in any way, just on your completion of this 10-question assessment (you won’t even see your score).
This is part of a pilot study within Carleton, and different students will be stronger or weaker in different areas (and your time since your last quantitative experience may impact your performance as well, as will your enjoyment of those experiences, etc.).
Here’s a link to the assessment: click me!!
Note that if at any time in this course you feel like you could use some extra support in quantitative skills, you can stop by the Quantitative Resource Center for drop-in tutoring or by appointment.
Part 1: Making a picture
# You should be fully equipped to complete this part after Lesson 4 (Monday Sep. 22).
In this part, you will guide the user through making a picture. For example, your program could instruct a user to make a house by following these steps:
- Click twice, indicating two corners of a rectangle for the house.
- Click once, indicating the center point of the top edge of the door, which has width 1/5 that of the entire house.
- Click once, indicating the center point of a circular window that has diameter half the width of the door.
- Click once, indicating the peak of the roof.
An example interaction might be the following sequence:

There should also be a text display at the bottom of the window, explaining the different steps to the user.
You can design any type of picture you want, as long as it follows these guidelines:
- There must be at least three different shapes used (different classes in
graphics.py). - You must set at least three attributes between all of the shapes (ex: fill color, outline color, border width).
- You must require at least five clicks from the user.
Your code should be saved in a file called picture.py. You should also include a screenshot of an example of your final picture after running your program in picture.png.
Part 2: Placing checkers pieces
# You should be fully equipped to complete this part after Lesson 4 (Monday Sep. 22).
For this part, you will display a grid representing a game board (like in checkers or chess, but you don’t need to color the grid locations red/black). You will be placing pieces such that there is one piece per row in the first column.
Drawing a grid
You should start by practicing displaying a grid. As seen in the earthquake visualization code from Friday, you can use the setCoords method of the GraphWin class to change the coordinate system to one you’re likely more familiar with.
Here is an example not changing the coordinates (assume graphics has already been imported):
...
# Make the window
win = GraphWin("Regular Coordinates", 400, 300)
# Draw an arrow
p1 = Point(100, 100)
p2 = Point(300, 200)
line = Line(p1, p2)
line.setArrow("last")
line.draw(win)
# Wait for the user to click, then exit
win.getMouse()
win.close()This is the result, alongside that of a program that also draws a grid (see below):

You can get the same arrow but use coordinates you’re more familiar with by using the setCoords method of the GraphWin class. To use this method, you should provide, in order, the minimum x, minimum y, maximum x, and maximum y values of the window. Here is an example of drawing the same arrow but changing the coordinates to what you might be used to:
...
# Make the window
win = GraphWin("Modified Coordinates", 400, 300)
win.setCoords(0.0, 0.0, 4.0, 3.0) # set the min/max coords
# Draw an arrow
p1 = Point(1, 2) # much easier to understand!
p2 = Point(3, 1)
line = Line(p1, p2)
line.setArrow("last")
line.draw(win)
# Wait for the user to click, then exit
win.getMouse()
win.close()Notice how the first point for the arrow is at (1,2) rather than (100,100). This is because instead of the bottom of the window being y=300, in the new coordinate system, the bottom is y=0 and the top is y=3.
You are now ready to draw the grid! Here is a snippet of code that uses a modified coordinate system to generate a grid. Note that setCoords is called with slightly different values to provide a little buffer on either side. The result is shown on the right, above.
...
# Make the window
win = GraphWin("A Grid!", 400, 300)
win.setCoords(-0.5, -0.5, 4.5, 3.5) # set the min/max coords, with buffer
# Draw some vertical lines
x = 0
y1 = 0
y2 = 3
line = Line(Point(x, y1), Point(x, y2))
line.draw(win)
x = 1
y1 = 0
y2 = 3
line = Line(Point(x, y1), Point(x, y2))
line.draw(win)
# TODO: add more lines (wouldn't a loop be great?)
# Draw some horizontal lines
x1 = 0
x2 = 4
y = 0
line = Line(Point(x1, y), Point(x2, y))
line.draw(win)
# TODO: add more lines
# Draw an arrow
p1 = Point(1, 2)
p2 = Point(3, 1)
line = Line(p1, p2)
line.setArrow("last")
line.draw(win)
# Add some helpful labels
blLabel = Text(Point(0, -0.2), "(0,0)")
blLabel.draw(win)
brLabel = Text(Point(4, -0.2), "(4,0)")
brLabel.draw(win)
ulLabel = Text(Point(0, 3.2), "(0,3)")
ulLabel.draw(win)
urLabel = Text(Point(4, 3.2), "(4,3)")
urLabel.draw(win)
# Wait for the user to click, then exit
win.getMouse()
win.close()What you should do
For this part, your program should first ask the user how many grid cells there are (let’s call this n), and then draw an nxn grid. For each row, you should draw a red circle in the first column. A radius of 0.35 times a grid cell size seems to look good.
Save your program in a file called checkersPieces.py.
Here is a possible output:

Part 3: The random library
# You should be equipped to complete this part after Lesson 4 (Monday Sep. 22).
Similar to the math library, Python provides some useful functionality for pseudo-random numbers in a library called random.
Here are some example functions, taken from the Python documentation:
import random # import the random library
# Fun with single random values
val = random.random() # random float: 0.0 <= x < 1.0
print(val) # what I got: 0.37444887175646646
val = random.uniform(2.5, 10.0) # random float: 2.5 <= x < 10.0
print(val) # what I got: 3.1800146073117523
val = random.randrange(10) # integer from 0 to 9 inclusive
print(val) # what I got: 7
val = random.randrange(0, 101, 2) # *even* integer from 0 to 100 inclusive
print(val) # what I got: 26
# Now playing with lists!
val = random.choice(['win', 'lose', 'draw']) # single random element from a sequence
print(val) # what I got: draw
# note that it doesn't print the ''
deck = 'ace two three four'.split() # nifty string method to make a list
random.shuffle(deck) # shuffle a list
print(deck) # what I got: ['four', 'two', 'ace', 'three']
val = random.sample([10, 20, 30, 40, 50], k=4) # four samples without replacement
print(val) # what I got: [40, 10, 50, 30]The random-number generators used by the random module are not truly random. Rather, they are pseudo random (so don’t ever use them to write security software!).
Part 4: Randomly placing checkers pieces
# You should be fully equipped to complete this part after Lesson 4 (Monday Sep. 22).
For this part, you will extend your checkersPieces.py functionality to randomly select where to place pieces such that there is one piece per row.
Start by making a copy of checkersPieces.py and naming it randomPieces.py. Change your code such that for each row, instead of placing the checkers piece in the first column, you should choose a random column to draw the checkers piece.
Here is a possible output:

Note that although you should only have one piece per row, there might be repeats in the columns, or empty columns.
Reflection
# You should be equipped to complete this part after finishing your assignment.
Were there any particular issues or challenges you dealt with in completing this assignment? How long did you spend on this assignment? Write a brief discussion (a sentence or two is fine) in your readme.txt file.
Here are some examples:
##### Reflection #####
# I couldn't figure out how to change the text in Part 1; I found the undraw() function in the graphics.py documentation PDF.
# I had issues drawing circles until I looked back at the earthquake program.
# I kept randomly choosing rows instead of columns.
# I spent 7 hours on this assignment.##### Reflection #####
# I had so much fun making my own picture in Part 1.
# Most of my trouble came from Part 2. I couldn't figure out how to draw the circles in the middle,
# and then I realized I had to add 0.5 to move them off of the lines.
# I spent 7 hours on this assignment.##### Reflection #####
# It went fine; I found what I needed in my notes and the graphics.py documentation.
# I spent 5 hours on this assignment.Grading
This assignment will be graded out of 100 points, as follows:
- 10 points - complete the Quantitative Literacy Reasoning Assessment by Monday 9/22 at 10pm (Part 0)
- 5 points - submit all files to Gradescope with correct names
- 5 points - all code files contain top-level comments with file name, purpose, and author names
- 5 points - each code files’ top-level comments contain collaboration statement
- 5 points - code style enables readable programs (Parts 1–4)
- 25 points -
picture.pyprogram uses three different shapes (4 pts), sets three attributes (4 pts), requires five user clicks (4 pts), draws shapes based on user clicks (8 pts), and gives instructions to the user (5 pts) (Part 1) - 10 points -
picture.pngis a valid possible output from the program inpicture.py(Part 1) - 20 points -
checkersPieces.pyasks the user forn(3 pts), draws annxngrid (9 pts), and draws one piece per row (8 pts) (Part 2) - 10 points -
randomPieces.pybehaves likecheckersPieces.pybut draws in each piece in a random column (10 pts) (Part 4) - 5 points -
readme.txtfile contains reflection
What you should submit
You should submit the following files on Gradescope:
readme.txt(reflection)picture.py(Part 1)picture.png(example result from Part 1)checkersPieces.py(Part 2)randomPieces.py(Part 4)