Due: Never
practice1.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 should reject your submission entirely if you do.
Like in homework, we will be checking your code based on whether it follows the 15-112 style guide. Gradescope may deduct points from your overall score 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 has already started, so this is also a way to practice your good style!
carrylessAdd(x, y)
that takes two non-negative integers x and y and returns their carryless sum. As the paper demonstrates, carrylessAdd(785, 376)
returns 51.
destructiveRemoveRepeats(L)
, that removes any repeating
elements in L, destructively. Thus, this function should directly modify the
provided list to not have any repeating elements. Since this is a destructive
function, it should not return any value at all (so, implicitly, it should
return None).
For example:
patternedMessage(message, pattern)
that takes two strings, a message and a pattern, and returns a string produced by replacing the non-whitespace characters in the pattern with the non-whitespace characters in the message (where any leading or trailing newlines in the pattern are first removed). As a first example:
call | result |
patternedMessage("Go Pirates!!!", """ *************** ****** ****** *************** """) |
GoPirates!!!GoP irates !!!GoP irates!!!GoPira |
call | result |
patternedMessage("Three Diamonds!",""" * * * *** *** *** ***** ***** ***** *** *** *** * * * """) |
T h r eeD iam ond s!Thr eeDia monds !Th ree Dia m o n |
patternedMessage("Go Steelers!", """ oooo$$$$$$$$$$$$oooo oo$$$$$$$$$$$$$$$$$$$$$$$$o oo$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$o o$ $$ o$ o $ oo o$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$o $$ $$ $$o$ oo $ $ '$ o$$$$$$$$$ $$$$$$$$$$$$$ $$$$$$$$$o $$$o$$o$ '$$$$$$o$ o$$$$$$$$$ $$$$$$$$$$$ $$$$$$$$$$o $$$$$$$$ $$$$$$$ $$$$$$$$$$$ $$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$ $$$$$$$$$$$$$$ '$$$ '$$$'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ '$$$ $$$ o$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ '$$$o o$$' $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$o $$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$' '$$$$$$ooooo$$$$o o$$$oooo$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ o$$$$$$$$$$$$$$$$$ $$$$$$$$'$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$' '''' $$$$ '$$$$$$$$$$$$$$$$$$$$$$$$$$$$' o$$$ '$$$o '$$$$$$$$$$$$$$$$$$'$$' $$$ $$$o '$$'$$$$$$' o$$$ $$$$o o$$$' '$$$$o o$$$$$$o'$$$$o o$$$$ '$$$$$oo '$$$$o$$$$$o o$$$$' '$$$$$oooo '$$$o$$$$$$$$$' '$$$$$$$oo $$$$$$$$$$ '$$$$$$$$$$$ $$$$$$$$$$$$ $$$$$$$$$$' '$$$' """)
GoSteelers!GoSteeler s!GoSteelers!GoSteelers!GoS teelers!GoSteelers!GoSteelers!GoS te el er s ! Go Steelers!GoSteelers!GoSteelers!GoSteel er s! GoSt ee l e rs !GoSteeler s!GoSteelers! GoSteelers !GoSteel ers!GoSte elers!GoSt eelers!GoSt eelers!GoSt eelers!G oSteele rs!GoSteele rs!GoSteele rs!GoSteelers!GoSteeler s!GoSteelers!GoSteelers !GoSteelers!G oSteelers!GoSt eele rs!GoSteelers!GoSteelers!GoSteelers!GoSteelers!GoSteel ers! GoS teelers!GoSteelers!GoSteelers!GoSteelers!GoSteelers !GoSt eele rs!GoSteelers!GoSteelers!GoSteelers!GoSteelers!GoSt eele rs! GoSteelers!GoSteelers!GoSteelers!GoSteelers!Go Steelers!GoSteele rs!GoSteelers !GoSteelers!GoSteelers!GoSteelers!GoS teelers!GoSteelers !GoSteelers!G oSteelers!GoSteelers!GoSteelers!Go Steel ers! GoSt eelers!GoSteelers!GoSteelers!G oSte elers !GoSteelers!GoSteelers! GoS teel ers!GoSteel ers! GoSte elers !GoSte elers!GoSteele rs!Go Steelers !GoSteelers! GoStee lers!GoSte elers!GoSteeler s!GoSteele rs!GoSteel ers!GoSteele rs!GoSteeler s!GoSteeler s!GoS
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:
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: