By hw 5.1's deadline, everyone must have completed a 5-minute meeting (yes, just 5 minutes, though they may expand to 10 minutes at your TA's discretion) with one of the TA's from your assigned recitation, to begin a discussion about your term project ideas. This is very brief, just to be sure you've started thinking about TP's at least a bit. You do not have to prepare for these meetings, but it would be nice (and probably more effective) if you showed up with some ideas about what you might want to pursue.
Early in this hw cycle, you will receive an email from your TA's with instructions about how to sign up for these meetings. Be sure to sign up right away, and be sure to be on time to these meetings. And move quickly, since they will be kept to 5 minutes, for real. So you know: They are worth 10 points in hw5.1, and the only way to get the points is to be on time. If you are late, or if you miss the meeting, you will not get the points, even if you have a make-up meeting. Of course, this does not include students with hw5.1 extensions for university-approved conflicts, or documented medical emergencies, etc.
These meetings are only to help you. But you can help yourself, too. Look over the gallery a bit. Get an idea of what constitutes a term project. And start thinking about what you might be interested in.
Starting from the Polynomial class here, edit that class and also implement the Quadratic class so that all the tests below succeed. Be sure not to hardcode against these tests, as the autograder will use similar tests, but with different constants. You are also responsible for understanding how the tests themselves work. For example, understand how the list of first-class functions is being used in testPolynomialAndQuadraticClasses, and also understand why the try/except calls are used in testQuadraticClass. Good luck!
def testPolynomialAndQuadraticClasses(): print("Testing Polynomial and Quadratic classes...") for testFn in [testPolynomialBasics, testPolynomialEq, testPolynomialStr, testPolynomialConstructor, testPolynomialInSets, testPolynomialTimesOperator, testPolynomialExponentiationOperator, testQuadraticClass ]: print(" Running %s..." % testFn.__name__, end = " ") testFn() print("Passed!") print("Passed all Polynomial and Quadratic Class tests!") def almostEqual(d1, d2): epsilon = 0.000001 return abs(d1 - d2) < epsilon def testPolynomialBasics(): p1 = Polynomial([2, -3, 5]) # 2x**2 -3x + 5 assert(type(p1) == Polynomial) assert(p1.degree() == 2) assert(p1.coeff(0) == 5) assert(p1.coeff(1) == -3) assert(p1.coeff(2) == 2) assert(p1.evalAt(0) == 5) assert(p1.evalAt(2) == 7) p2 = Polynomial([4, -3]) # Now test the + operator p3 = p1 + p2 # (2x**2 -3x + 5) + (4x - 3) == (2x**2 + x + 2) assert(type(p3) == Polynomial) assert(p3.evalAt(2) == 12) assert(p3.evalAt(5) == 57) def testPolynomialEq(): assert(Polynomial([1,2,3]) == Polynomial([1,2,3])) assert(Polynomial([1,2,3]) != Polynomial([1,2,3,0])) assert(Polynomial([1,2,3]) != Polynomial([1,2,0,3])) assert(Polynomial([1,2,3]) != Polynomial([1,-2,3])) assert(Polynomial([1,2,3]) != 42) assert(Polynomial([1,2,3]) != "Wahoo!") # A polynomial of degree 0 has to equal the same non-Polynomial numeric! assert(Polynomial([42]) == 42) def testPolynomialStr(): assert(str(Polynomial([1,2,3])) == "x^2 + 2x + 3") assert(str(Polynomial([-1,-2,-3])) == "-x^2 - 2x - 3") assert(str(Polynomial([42])) == "42") assert(str(Polynomial([-42])) == "-42") assert(str(Polynomial([0])) == "0") assert(str(Polynomial([1,0,-3, 0, 1])) == "x^4 - 3x^2 + 1") assert(str(Polynomial([1,0,-3, 0, 1])) == "x^4 - 3x^2 + 1") assert(str(Polynomial([-1,0,3, 0, -1])) == "-x^4 + 3x^2 - 1") def testPolynomialConstructor(): # If the list is empty, treat it the same as [0] assert(Polynomial([]) == Polynomial([0])) assert(Polynomial([]) != Polynomial([1])) # Remove leading 0's assert(Polynomial([0,0,0,1,2]) == Polynomial([1,2])) assert(Polynomial([0,0,0,1,2]).degree() == 1) # Require that the constructor be non-destructive coeffs = [0,0,0,1,2] assert(Polynomial(coeffs) == Polynomial([1,2])) assert(coeffs == [0,0,0,1,2]) def testPolynomialInSets(): s = set() assert(Polynomial([1,2,3]) not in s) s.add(Polynomial([1,2,3])) assert(Polynomial([1,2,3]) in s) assert(Polynomial([1,2,3]) in s) assert(Polynomial([1,2]) not in s) def testPolynomialTimesOperator(): # (x**2 + 2)(x**4 + 3x**2) == (x**6 + 5x**4 + 6x**2) assert(Polynomial([1,0,2]) * Polynomial([1,0,3,0,0]) == Polynomial([1,0,5,0,6,0,0])) # (x**3 - 3x + 5) * 10 == (10x**3 - 30x + 50) assert(Polynomial([1,0,-3,5]) * 10 == Polynomial([10,0,-30,50])) # Hint: to do multiplication this way, you have to use __rmul__, # which should just call __mul__ (yes, really) assert(10 * Polynomial([1,0,-3,5]) == Polynomial([10,0,-30,50])) def testPolynomialExponentiationOperator(): assert(Polynomial([1,2,3])**0 == 1) assert(Polynomial([1,2,3])**1 == Polynomial([1,2,3])) assert(Polynomial([1,2,3])**2 == Polynomial([1,2,3]) * Polynomial([1,2,3])) assert(Polynomial([1,2,3])**3 == Polynomial([1,2,3]) * Polynomial([1,2,3]) * Polynomial([1,2,3])) def testQuadraticClass(): q1 = Quadratic([3,2,1]) # 3x^2 + 2x + 1 assert(type(q1) == Quadratic) assert(q1.evalAt(10) == 321) assert(isinstance(q1, Quadratic) == isinstance(q1, Polynomial) == True) # the determinant is b**2 - 4ac assert(q1.determinant() == -8) # use the determinant to determine how many real roots (zeroes) exist assert(q1.numberOfRealRoots() == 0) assert(q1.getRealRoots() == [ ]) # Once again, with a double root q2 = Quadratic([1,-6,9]) assert(q2.determinant() == 0) assert(q2.numberOfRealRoots() == 1) [root] = q2.getRealRoots() assert(almostEqual(root, 3)) # And again with two roots q3 = Quadratic([1,1,-6]) assert(q3.determinant() == 25) assert(q3.numberOfRealRoots() == 2) [root1, root2] = q3.getRealRoots() # smaller one first assert(almostEqual(root1, -3) and almostEqual(root2, 2)) # And make sure that these methods were defined in the Quadratic class # and not in the Polynomial class (we'll just check a couple of them...) assert('evalAt' in Polynomial.__dict__) assert('evalAt' not in Quadratic.__dict__) assert('determinant' in Quadratic.__dict__) assert('determinant' not in Polynomial.__dict__) testPolynomialAndQuadraticClasses()
During last's week recitation, we developed the animation for flappy bird. If you have forgotten how Flappy Bird Animation works, here is an implementation. Note though that instead of using the mouse to keep the bird flapping, we've used the Space bar.
Here, we want to re-write the flappy bird animation using objects. You should create two classes: The Bird Class and the Obstacle Class. The Bird class should have at least a draw() and move() method, while the Obstacle Class should have at least a draw(), move(), and isColliding() method.
In addition, as we mentioned in lecture, the attributes of an object should never be directly changed, so make good use of observer methods and modifier methods. If you fail to adhere to this, you will loose points.
Here's a few more specifications/features for this game:
Make sure to put all of the animation code for Flappy bird below the #ignore_rest line!