Governor's Career & Technical Academy Arlington

Introduction to Computer Science: Week 9


We will only meet once this week, and we will use that meeting to complete our investigation of regular expressions.

Thursday, March 5th


The plan for today is:

  1. Share pair presentations on regular expression topics assigned last week.
  2. Decide on an approach to extracting coefficents and exponents from our string representation of a polynomial.
  3. Plan for next steps in the project.

We will decide on appropriate homework together as part of the last step.


Using Adrian's regular expression as a starting point, write a Python program to extract coeffients and exponents from a string representation of a polynomial. Bonus if you and your partner can use TDD to do it.

def get_terms(polystr):
    Create a list of 2-tuples of coefficents and exponents of a polynomial

      >>> extract_polynomial('3x^4+7x^2')
      [(3, 4), (7, 2)]
      >>> extract_polynomial('x^9-3x^4-x+42')
      [(1, 9), (-3, 4), (-1, 1), (42, 0)]


You will be evaluated based on your solution to this problem and the presentation of it you provide in class on Monday.