CS21 In Class: week 3

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

Setting up a subdirectory for week 3 in-class work

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

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

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

$ cp ~newhall/public/cs21/week03/* .
$ ls
  format.py  is_odd.py  stars.py  starword.py  test_math.py 

Weekly In-class Examples

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

  1. Try out the string accumulator pattern problem that we did in class last Thursday on the whiteboard. (starword.py)

    To open starword.py in vim:

    $ vim starword.py  
    
    I often run the program in another terminal window (so I can view the program in vim in one window as I run in another window).
    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/week03
    $ ls 
      format.py  is_odd.py  stars.py  starword.py  test_math.py 
    
    $ python starword.py  
    

  2. Together we are going to write a program that determines of a number entered by the user is odd or even. (is_odd.py)

  3. Together we are going to try out some pattern of stars problems. (stars.py)

  4. If we have time, we will look at the print function and formated ouput and how to use the math library. (examples in format.py, test_math.py)