In Class: Week 6
Create a week06 subdirectory in your cs21/class directory:
% cd cs21/class
% mkdir week06
Then, from within your week06 subdirectory copy over some python files
from my public directory:
% cd week06
% cp ~newhall/public/cs21/week06/* .
We are going to do some of the following together in class:
Practice with while loops
- open syracuse.py in vim. We will finish the code in main
to compute the Syracuse sequence for an integer value entered by
- open fivequestions.py. We will write the getYesOrNo function together.
- open primefactors.py. Together we are going to write
a function that prints out the prime factors of a given number.
A run of the program might look like this:
This program prints out the prime factors of a given number
Enter an integer value: 60
The prime factors of 60 are:
2, 2, 3, 5,
Some practice with functions with list and object parameters:
- open squareevens.py. We are going to add two functions: printList,
that takes a list of integers and prints it to the terminal; and
takes a list of integers and squares all the even elements in the list.
Now let's change squareEvens so that it returns the number of elements
it changed in the list.
- open changecircle.py. We are going to write a function, that
takes a Circle object, a color and x and y coordinates, and moves
the circle to the x, y coordinate and changes its color.
strings and lists as objects, and the random library:
- On the class schedule for week6 is a link to information about
using strings and lists as objects, and about using the random library.
Read through this, and look at the sample code that you copied over
from my week06 subdirectoy. We will talk about using lists and strings
as objects in class, but you may want to look at this and try out some
of the example code you copied over (stringOps.py, listOps.py, randomOps.py).