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	          
  /home/your_user_name/cs21/class

$ mkdir week02                      # make a subdirectory named week02   
$ cd week02                         # cd into it
$ pwd           
  /home/your_user_name/cs21/class/week02

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.
    (expr.py)

    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
      /home/your_user_name/cs21/class/week02
    $ 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
    (test_math.py).

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

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