Problem Set 2 - Due Mon, Feb 13 at 23:59

Reading and helpful Information

  1. The CS111 Problem Set Guide gives an overview of psets, including a detailed description of individual and partner tasks
  2. Goldwasser & Letscher, Chapter 3, sections 3.3-3.6, pages 103-110
  3. Slides and notebooks from Lec 2 and Lec 3.
  4. Problems and solutions from Lab 2 and Lab 3
  5. Our CS 111 Code Style Guide, which has been updated with information about functions.

About this Problem Set

This problem set will give you practice with abstraction, problem-solving by recognizing patterns, and functions.

  1. In both tasks you will create your own functions and practice breaking down a problem into simpler parts.
  2. Students with last names from M to Z are expected to make use of the CS 111 Google Group this week to either ask a question or answer one.
  3. Pair programming: Use this shared Google Doc to find a pair programming partner and record who your pair partner is. Please do not use cs111-spring17 to find partners.

  4. Collaboration and honor code: you can talk with other individuals and teams about high-level problem-solving strategies, but you cannot share any code with them.
  5. The CS111 Problem Set Guide gives an overview of psets, including a detailed description of individual and partner tasks.
  6. PS02 FAQ covers the most common issues students encounter when working on PS02, consult it before asking in the Google Group.
  7. Follow the practices discussed in our CS111 Code Style Guide.
  8. In previous semesters, students spent in average 3.2 hours on Task 1 (min = 1 hour, max = 10 hours) and 3.6 hours on Task 2 (min = 1 hour, max = 9 hours).

All code for this assignment is available in the ps02 folder in the cs111/download directory within your cs server account. This assignment also uses the Otter Inspector program that you encountered in Lab 3, to help you do a final check of Task 1 and your Honor Code form before you submit.


Task 1: Diamond Pattern

This is an individual problem which you must complete on your own, though you may ask for help from the CS111 staff.

In the provided diamonds.py, define a zero-parameter function named diamondPattern. When diamondPattern is invoked in the interactive pane, it should display the following pattern of asterisks:

  *         *         *         *
 * *       * *       * *       * *
* * *     * * *     * * *     * * *
 * *       * *       * *       * *
  *         *         *         *
       *         *         *         *
      * *       * *       * *       * *
     * * *     * * *     * * *     * * *
      * *       * *       * *       * *
       *         *         *         *
  *         *         *         *
 * *       * *       * *       * *
* * *     * * *     * * *     * * *
 * *       * *       * *       * *
  *         *         *         *
       *         *         *         *
      * *       * *       * *       * *
     * * *     * * *     * * *     * * *
      * *       * *       * *       * *
       *         *         *         *
  *         *         *         *
 * *       * *       * *       * *
* * *     * * *     * * *     * * *
 * *       * *       * *       * *
  *         *         *         *
       *         *         *         *
      * *       * *       * *       * *
     * * *     * * *     * * *     * * *
      * *       * *       * *       * *
       *         *         *         *
  *         *         *         *
 * *       * *       * *       * *
* * *     * * *     * * *     * * *
 * *       * *       * *       * *
  *         *         *         *
       *         *         *         *
      * *       * *       * *       * *
     * * *     * * *     * * *     * * *
      * *       * *       * *       * *
       *         *         *         *

In Canopy, open diamonds.py. Notice that it contains the following variable definitions.

# pre-defined strings
zeroStar  = '     '
oneStar   = '  *  '
twoStar   = ' * * '
threeStar = '* * *'
empty     = ''

Notes


At the very end, once you're satisifed with your diamondPattern function, open the otterInspect.py file in your ps02 folder. You needn't look at the content of this file (and you must not modify it); just Run it using the green play button on Canopy. It should bring up a web page evaluating whether your diamond pattern matches the expected one. This is a good way to check for any unexpected errors before you submit your code.

Notice that the page will also tell you that your Honor Code form values are missing. Ignore it for now; you will fill out the honor code in Task 3.

On some web browsers, Otter Inspector will open a new tab each time you run it. To avoid confusion, close the web page that it opens after you have looked at it.

Task 2: Eyes Eyes Eyes

This task is a partner problem in which you are required to work with a partner as part of a two-person team.

Your goal is this task is to generate the following picture:


As you can imagine, you'll need an incremental approach to solving this problem. First you write code to create a single face (implemeted with a Layer) and position it in its correct position on the canvas. Then, you decide on how to abstract over this code by converting it into a function with parameters that can generate every face. You'll call this function eyes. In order to generate the entire image, you'll write a second function, eyesPicture (a zero-parameter function), which will call the eyes function eight times to draw each face on the Canvas object. Initial code for the structure of the eyesPicture and how to test it are given in the file eyes.py.

Specifications for drawing a face

Problem-solving: Start on paper

We recommend that before opening Canopy, you complete the following steps with paper and pen. (Of course, working with your partner.)

Incremental Development

Now that you have solved the problem on paper, you can start implementing this solution with Python code. But, you still have to do that incrementally, to make sure that you are not making mistakes, which are harder to find if you write first the entire code.

Final Steps

def eyesPicture():
    """Function to generate the complete image. Creates a new Canvas object
    when invoked. Returns this object.

    Example:
        In [1]: myPicture = eyesPicture()
        In [2]: myPicture.close()
    """
    canvas = Canvas(...)
    # Add all eight eye patterns to the canvas.
    canvas.add(eyes(...)) # 1st eye pattern
    canvas.add(eyes(...)) # 2nw eye pattern
    canvas.add(eyes(...)) # 3rd eye pattern
    canvas.add(eyes(...)) # 4th eye pattern
    canvas.add(eyes(...)) # 5th eye pattern
    canvas.add(eyes(...)) # 6th eye pattern
    canvas.add(eyes(...)) # 7th eye pattern
    canvas.add(eyes(...)) # 8th eye pattern

    return canvas

Task 3: Honor Code Form

Rather than filling out a Google Form for your honor code submission as you did last time, you will enter those values into the appropriate variables in the honorcode.py file.

Remember to run otterInspect.py one final time before you submit to check that your diamonds program works, and that your honor code form is complete.


How to turn in this Problem Set

Soft-copy submission

Hard-copy submission

There is no hard copy submission. Problem set submission is entirely electronic.