Due Sunday 13-Feb, at 10:00pm
While you may submit to Gradescope as often as you like for this assignment, some questions are not autograded, so you will be responsible for testing your code and making sure it meets the problem requirements. As stated in the style guide, you do not have to write test cases for interactive, random, graphics, data initialization or event functions. Instead, you should test by visually inspecting your code’s behavior as you complete steps of each problem, where reasonably possible. This will make debugging your code much easier.
hw5.py
file includes test functions to help you test on your own before
you submit to Gradescope. When you run your file, problems will be tested in order. If
you wish to temporarily bypass specific tests (say, because you have not yet completed
some functions), you can comment out individual test function calls at the bottom
of your file in main()
. However, be sure to uncomment and test everything together
before you submit! Ask a CA if you need help with this.Do not use sets, dictionaries, try/except, classes, or recursion this week. The autograder (or a manual CA review later) will reject your submission entirely if you do.
Like in the previous assignment, we will be grading your code based on whether it follows the 15-112 style guide. We may deduct up to 10 points from your overall grade for style errors. We highly recommend that you try to write clean code with good style all along, rather than fixing your style issues at the end. Good style helps you code faster and with fewer bugs. It is totally worth it. In any case, style grading already started, so please use good style from now on!
You will notice that the skeleton file only includes testcases for some of the functions you are writing. You should write testcases for the others. (You can find some nice ways to test in the write-up below, but you will need to translate those to actual testcases.)
isRotation(s, t)
that takes two possibly-empty strings and returns True if one is a rotation of the other. Note that a string
is not considered a rotation of itself.gradebook
is a multiline string where each row contains a student's name (one
word, all lowercase) followed by one or more comma-separated integer grades. A gradebook
always contains at least one student, and each row always contains at least one grade. Gradebooks
can also contain blank lines and lines starting with the "#" character, which should be ignored.
bestStudentAndAvg(gradebook)
, that takes a gradebook and
finds the student with the best average (ignoring the case where there is a tie) and returns a
string
of that student's name followed by
a colon (":") followed by his/her average (rounded
to the nearest integer). For example, here is
a test case:
s.split(",")
and s.splitlines()
in your solution.
extractAssignStatements(text)
that extracts all
valid assignment statements from string text
. A valid assignment
statement is of the form lhs=rhs
. The left-hand side (lhs) of the
statement must be a variable name. For simplicity, only alphabetical characters
are allowed in the variable name (that is, no numbers or symbols). The
right-hand side (rhs) must be a non-negative integer. Between both sides, only
the character '=' or spaces can occur.
The function should return a list of tuples, (lhs, rhs) where lhs is a string and rhs is an integer.
Here are some examples:
drawNiceRobot(canvas, width, height)
that (you guessed it!) draws a nice robot!
This is not meant to be very difficult. We just want to see some really cool robots while grading your homework. Your function must make a drawing using the 112 graphics library that meets the following criteria:
basic_graphics
. Have fun!
Write the function drawUnitedStatesFlag which draws the US flag in the provided dimensions. You can assume that the height:width ratio will be 10:19, as is the case with the actual US flag.
You can find much useful information about the flag’s dimensions on Wikipedia:
https://en.wikipedia.org/wiki/Flag_of_the_United_States, but we do not expect you to match the actual US flag design perfectly; you should instead seek to create a reasonable approximation of the flag. However, your flag must meet the following requirements:
The flag should start from the upper left-hand corner of the window.
The flag should have the correct number of stripes, alternating red and white in the correct order.
The blue field in the upper left corner should cover exactly seven stripes and have a reasonably correct width.
You can use circles instead of stars. If you use stars you get 5pts bonus.
The flag should have the correct number of circles/stars in the correct configuration, with the circle/star size and spacing reasonably close to the actual flag.
The colors should be the correct shades of red and blue. (Check Wikipedia)
For an example of what reasonable flags might look like, here is an example: