Problem Set 8 - Due Mon, Apr 10 at 23:59 EST

Reading

  1. Slides and notebooks from Lec 13, Turtle Recursion, Lec 14, Fruitful Recursion

  2. Lab 9, Fruitful Recursion

  3. Think Python, Sec 5.8--5.10: Recursion

  4. Think Python, Ch. 6: Fruitful Functions (includes more on Recursion, plus other useful information)

About this Problem Set

This problem set has two goals: (1) to give you practice with fruitful recursion; and (2) to give you an introduction to HTML and CSS that will be useful for displaying results from analysis of data from Web APIs (the lecture topic on Thu. Apr. 6 and Mon. Apr. 10).

There are three tasks in this problem set:

  1. In Task 1, you will learn about HTML and CSS in the context of some exercises. You should complete this task by Sun. Apr. 9, since knowledge of HTML and CSS will be useful for the Web API II lecture on Mon. Apr. 10.

  2. In Task 2 (Individual Task), you will define a fruitful recursive function that draws a pattern using Turtle World and returns information about the pattern.

  3. In Task 3 (Partner Task), you will generate quilts with a recursive pattern. Use this shared Google Doc to find a pair programming partner.

    • Remember that you can work with the same partner a maximum of TWICE this semester.

    • We will deduct 2 points per day for any students who have not recorded their names on the pair programming google doc by Thursday, Apr 6th at 11:59pm

 

The CS111 Problem Set Guide gives an overview of psets, including a detailed description of individual and partner tasks.

In Fall 2016, students spent these times:

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

 


Task 1: Introduction to HTML and CSS

In this particular lab-like task, you should mostly work on your own, but you are allowed to ask for help from fellow students as well as from the CS111 staff

In this task, you will complete some exercises involving HTML (the language describing the structure of a web page) and CSS (the language describing the visual display of a web page).

In many semesters, we have covered this material in a lab. But because of constraints in this semester's schedule, we do not have a slot for an HTML/CSS lab. So we're asking you to complete the HTML/CSS lab exercises as part of PS08. (We have removed a third recursion problem to make room for this material.)

For this task, you should do the following:

  1. Read the HTML/CSS lab introduction

  2. Follow the instructions for the Part 1. HTML subtask. This involves creating a file top5.html in your ps08 folder.

  3. Follow the instructions for the Part 2. CSS subtasks. This involves:

    • creating a file top5.css in your ps08 folder.

    • publishing your top5.html and top5.css files in your public_html folder in your account on cs.wellesley.edu.

Note:

There are no Otter Inspector tests for this task. You should manually verify the following

 


Task 2: Turtle Shrubs

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

In this task, you'll write a fruitful recursive function named shrub that draws a tree pattern with a turtle and returns a tuple of values (see below for details). Your shrub function should be invariant with respect to the turtle's position and direction. Define your function in the shrub.py file in the ps08 folder.

A turtle shrub is a variation of the turtle tree in Lecture 13 (slides 13-40 through 13-75). It is created by the shrub function, which takes four parameters in order:

  1. trunkLength: the length of the branch at the base of the shrub.
  2. angle: the angle relative to the trunk for the right and left branches
  3. shrinkFactor: the trunk of the right branch is shrinkFactor times trunkLength, and the trunk of the left branch is shrinkFactor*shrinkFactor times trunkLength
  4. minLength: the minimum branch length in the shrub.

The shrub function returns a pair (a tuple with two elements) of:

  1. The total number of branches in the shrub, including the trunk
  2. The total length of branches in the shrub, including the trunk

 

Below are sample invocations of the shrub function, with the magenta text indicating the value returned by the invocation, i.e., the number of branches in the shrub:

shrub(100, 15, 0.8, 60) -> (4, 308.0)
shrub(100, 15, 0.8, 50) -> (7, 461.6)
shrub(100, 15, 0.8, 10) -> (232, 3973.9861913600025)
shrub(100, 30, 0.82, 10) -> (376, 6386.440567704483)
shrub(200, 90, 0.75, 10) -> (232, 5056.675148010254)

Notes:

 


Task 3: Quilts with Recursion

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

You will write a program that generates quilts like this:

The ps08 folder contains picture.py, our module built upon cs1graphics where every object is a 200x200 "picture." The module includes several functions to generate and combine pictures, such as upperRightNest that we saw in lecture 14, fourPics and rotations that you saw earlier in the course, and others.

The recursiveQuilts.py file includes the following predefied pictures that you can use as building blocks for your patterns:

pyTri
gwTri
redLeaves
greenLeaves
emptyPic

Write all your code for this task in the recursiveQuilts.py file.

Task 3(a). quadRecurse

Define a function, quadRecurse(pic1, pic2, levels), that generates the following pictures:

quadRecurse(pyTri, gwTri, 1)
quadRecurse(pyTri, gwTri, 2)
quadRecurse(pyTri, gwTri, 3)
quadRecurse(pyTri, gwTri, 4)
quadRecurse(pyTri, gwTri, 5)
quadRecurse(pyTri, gwTri, 6)

quadRecurse(pyTri, gwTri, 0) should be an empty picture:

Notes:

Task 3(b). quilt

Now define a function, quilt(pic1, pic2, levels), that generates the following pictures. quilt is not a recursive function, and is very short. (The function body can be written in one (rather long) line, but you may want to express it in several lines). You will need to invoke quadRecurse, as well as at least two of the functions from picture.py.

Carefully study the relationship between the patterns produced by quadRecurse and quilt for the same number of levels.

quilt(pyTri, gwTri, 1)
quilt(pyTri, gwTri, 2)
quilt(pyTri, gwTri, 3)
quilt(pyTri, gwTri, 4)

(Note: invoking quilt with levels4 may cause your program to freeze.)

quilt(pyTri, gwTri, 0) should be an empty picture as well.

quilt(redLeaves, greenLeaves, 4) generates the picture shown at the beginning of the task.

Uncomment the test invocations at the bottom of recursiveQuilts.py to test your functions. Type closeAllPics() in the interactive pane to close the picture canvases without crashing Canopy.


Task 4: Honor Code Form and Final Checks

As in the previous problem sets, your honor code submission for this pset will involve defining entering values for the variables in the honorcode.py file. This is a Python file, so your values must be valid Python code (strings or numbers).

If you wrote any function invocations or print statements in your Python files to test your code, please remove them, comment them out before you submit, or wrap them in a if __name__=='__main__' block. Points will be deducted for isolated function invocations or superfluous print statements.

Remember to run otterInspect.py one final time before you submit to check that your shrub.py program work as intended, and that your honor code form is complete. While running your code through otterInspect is not required, it is highly recommended since it may catch errors that you haven't noticed. However, many parts on this pset are not tested by Otter Inspect, and you need to test those parts on your own to verify that they are working properly.

If you have issues running otterInspect.py, first check for the following common issues.

If you are unable to resolve this issue after going through this checklist, seek help from any of the course staff.


How to turn in this Problem Set