In Class: Week 3


Create a week03 subdirectory in your cs21/class directory:

      % cd 
      % cd cs21/class
      % pwd
        /home/your_user_name/cs21/class

      % mkdir week03        
	
Then, from within your week03 subdirectory copy over some python files from my public directory:
    % cd week03
    % pwd
      /home/your_user_name/cs21/class/week03

    % cp ~newhall/public/cs21/week03/* .
    % ls
      ascii.py   drop_letter.py   format.py   is_odd.py   what_is_it.py
	

We are going to do some of the following this week:
  1. open ascii.py. Together we are going to write a program that takes a line of input from the user, and prints out the ascii values of each character in the input string. Here is what a run of your program might look like:
    $ python ascii.py
    
    Enter a phrase: hello there
    
    h : 104
    e : 101
    l : 108
    l : 108
    o : 111
      : 32
    t : 116
    h : 104
    e : 101
    r : 114
    e : 101
    

  2. open drop_letter.py. Together we are going to write a program that takes a line of input from the user, and creates a new string that consists of every other character (every even character) from the input string (we will say that zero is even). Here is what a run of your program might look like:
    This program takes as input a string and produces a new
    string cosisting of every other (even) character from the first
    
    Enter a phrase: I love computer science! 
    The modified string is: Ilv optrsine
    

  3. open what_is_it.py. Together we are going to complete the program that asks the user to enter a character from the keyboard and then tells the user what type of character it is (lower case, upper case, digit, or other).

    Once you get that working add code to check that the user correctly entered just a single character. If not, then print out an error message saying that the input is bad and quit the program by making a call to the exit function:

    print "bad input"  # come up with a better message than this
    exit()
    

  4. open is_odd.py. Write a program that asks the user to enter an integer value and then prints out a message indicating if the value is odd or not.

    Once you get that to work, lets add code to first check to see if the input value entered by the user is a valid int (e.g. the string "hello" is not a valid int value). If the input is not valid, print out an error message and exits. If it is valid, then print out a message indicating if it is an odd or even number.

  5. open format.py in vim. It contains some examples of formated output. Try running it in another terminal window and see if you understand what is getting printed out.