In Class: Week 6, Thursday


Run update21 to copy example programs to your cs21/class/week06 directory. From there, move to your week06 directory:

    $ update21
    $ cd 
    $ cd cs21/class/week06
    $ pwd
      /home/your_user_name/cs21/class/week06
    $ ls
      coinFlip.py	  grades_soln.py  squareevens.py       syracuse.py
      fivequestions.py	  listOps.py	  squareevens_soln.py  syracuse_soln.py
      grades.py		  randOps.py	  stringOps.py
	

We are going to do some of the following together in class:

    While loops

  1. Open fivequestions.py. We will write a function getYesOrNo that will ask a user to provide string input until we obtain a proper answer.

    strings and lists as objects

  2. On the class schedule for week6 is a link to information about using strings and lists as objects. 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).

    the random library

  3. Open up coinFlip.py. Let's create a program that flips a virtual coin over and over until we obtain 10 heads

  4. One of the files you copied over, randomOps.py, contains some examples of using the random library. We will start by looking at the documentation about using the random library off the week6 schedule, and then take a look at this code and running it to make sure we understand what it is doing.

  5. Now let's add a new function, createRandomList, to squareevens.py. This is a function that will return a list of some some number of elements between 10 and 20 (use the random library to pick the number of elements value), where each element in the list is some value between 0 and 1000 (again, use the random library to pick the value of each item you add to the list).

    Next, let's change the main function to make a call to our new function to create the list, main should print the list out, call squareEvens, and then print out the list again.