CS21 In Class: week 2

numeric types, expressions, strings, lists, more for loops

Setting up a subdirectory for week 2 in-class work

cd into your cs21/class/ subdirectory and create a new directory named 'week02', then cd into that directory:
$ cd cs21/class                     # cd into your cs21/class subdirectory
$ pwd	          

$ mkdir week02                      # make a subdirectory named week02   
$ cd week02                         # cd into it
$ pwd           

Now copy over all the files from my public/cs21/week02 directory into your week02 directory (remember to add the dot as the destination of the cp command). From your week02 directory:

$ cp ~newhall/public/cs21/week02/* .
$ ls
  expr.py  format.py  test_math.py  test_string.py

Weekly In-class Examples

This week we will do some of the following in class:

  1. Look at some examples of numeric types, operators, and expressions.

    To open expr.py in vim:

    $ vim expr.py  

    To run it (make sure you are in the correct subdirectory, pwd tells you which directory you are in and ls shows the contents of the directory):
    $ pwd
    $ ls 
      expr.py  format.py  test_math.py  test_string.py
    $ python expr.py

  2. Together we are going to write a program that computes the average of 5 int values.

  3. Briefly look at how to use some math library functions

  4. Write some code using string operators (concatenation(+), repetition(*), split([pos1:pos2]).

  5. If we have time, we will look at the print function and formated ouput.
    (examples in format.py)