Assignment 4
Prologue
This is a group assignment. Be sure to review our Code of Conduct for pair programming and be careful to adhere to it when working on the assignment. Keep in mind that you both must be authors of all code submitted.
Problem 1: Trominos
A tromino is a shape that consists of three squares. In this problem, you will write a program to draw various trominos to a graphics window that looks something like the following:
In this problem, you must implement two helper functions named draw_square
and draw_tromino
. You should also include a main
function that creates a graphics window and uses these helper functions to draw trominos.
Start by creating a file named trominos.py
and copy and paste the following code into it. The docstrings for the helper functions draw_square
and draw_trominos
are already provided for you.
from graphics import *
def draw_square(x, y, width, color, win):
"""Draws a square at (x,y) with the given width and color
Parameters:
x, a number
y, a number
width, a number
color, a string
win, a GraphWin object
Returns:
Nothing; called for the side effect
Postconditions:
* A square is drawn on the GraphWin object
* The square's color is the color given
* The width and height of the square is the width given
* The upper left corner of the square is at the point (x,y)
"""
pass # Replace this statement with your code
def draw_tromino(x, y, width, color, win):
"""Draws a tromino at (x,y) with the given width and color
Parameters:
x, a number
y, a number
width, a number
color, a string
win, a GraphWin object
Returns:
Nothing; called for the side effect
Postconditions:
* Three squares are drawn on the GraphWin object to compose an
L-shaped tromino
* The squares' colors are the color given
* Each square has a side-length of width/2
* The upper left corner of the tromino is at the point (x,y)
"""
pass # Replace this line with your code
def main():
pass # Replace this line with your code
main()
Problem 2: Visualizing Subtraction
In this problem, you will write a program called subtraction_viz.py
that shows a graphic that visualizes subtraction. When your program is run, it should prompt the user to type in two numbers x
and y
like the following:
Enter a number, x, such that 0 <= x <= 100: 90
Enter a number, y, such that 0 <= y <= x: 10
Here the user typed in 90
and 10
, respectively. After the user types in these numbers, your program should immediately display a visual that looks like the following:
Your graphics window need not look exactly like the one above. For example, you may choose different colors, font styles, etc., but the visual must clearly demonstrate subtraction and include textual labels that include the values typed in.
Your program should also have the following form:
# A program that visualizes subtraction
#
# Authors:
# YOU AND YOUR PARTNER'S NAMES GO HERE
from graphics import *
# Any helper functions go here
def main():
# Your program goes here
main()
Hint: I recommend creating a helper function called draw_column
that draws a single column, and then make use of it three times in your main
function. You should also document any helper functions with docstrings.
How to Turn in Your Code
- Once you are finished with the assignment, you should go to https://codepost.io and log into your account.
- Go to the CS 65 course.
- Go to Assignment 4 and upload all of your files.
- After you submit the assignment, you should be able to reopen it and see a Partners tab at the top of the submission page. Send the link to your partner and have them open it while logged in with their account.
- That’s it! You’ve just submitted your assignment.
Important Grading Criteria
I will evaluate your work with the following criteria in mind.
- Correctness. Does your code do what is asked? (e.g. named correctly, input and outputs correct values, etc.)
- Formatting. Is your code formatted so that it is easy to understand?
- Elegance. Is your code concise and elegant?
Partner Evaluation
After turning in your assignment, please fill out the following partner evaluation form. To do so, you will need to log into Google with your Drake username and password, and open the questionnaire.