Lecture 10 - Repetition


As usual, create two directories for today's class. Create a directory called lecture10 under activities, and a directory called lab10 under labs.


In-class Activity 1

Circles

In Lecture 9, you wrote a function that could draw a polygon of an arbitrary number of sides. Today, you are going to extend that mechanism to drawing circles.

Create a function called draw_circle_at in a file called circle.py. The function should draw a circle of the specified radius at the specified location. The function should vary the number of edges that make up the circle so that small circles have fewer sides and large circles have more sides. An easy way to do this is to assume that the side length is 1. Do not use the circle function in the turtle module.


Repetition

Last lab, we saw how we can use loops to simplify our code. Today, we will see how loops can make certain types of computations possible to create.


In-class Activity 2

Spirals

In a file called spirals.py, create a Python function called draw_spiral. This should draw a spiral at the specified location on the screen, similar to the image below.


The Wall of Learning (Style)

So far, you have learned about proper variable names, and pre/post conditions. We have briefly talked about limiting lines to 80 characters as well. Today, we will talk more about code comments, as it pertains to what you should and should not comment.


Lab Assignment 10

Change

In Lab 8, you wrote a function that returns the smallest number of coins necessary to represent some amount of change. Copy that file into your lab10 directory, using the cp command:

cd ~/cs120/labs/lab10
cp ../lab8/change.py change_redux.py

Write a new function called average_change. This function should use a for loop to compute the average amount of change necessary to represent all values in the range [1,99].


Submission

When you have finished, create a tar file of your lab10 directory. To create a tar file, execute the following commands:

cd ~/cs120/labs
tar czf lab10.tgz lab10/

To submit your activity, go to cseval.roanoke.edu. You should see an available assignment called Lab Assignment 10. Only one of your pair should submit your activity. Make sure both partners are listed in the header of your file.

Do not forget to email your partner todays files!


Last modified: Wed Sep 18 14:48:30 EDT 2013