In Class: Week 1 Tuesday


Complete lab 0 before trying this.

If you want to try out a python program do the following (we will do something like this in class on Wednesday, so if you do not get through this, that is okay):

  1. create a subdirectory class in your cs21 directory:
          % cd 
          % cd cs21
          % mkdir class
          % cd class
          % pwd
    	
  2. create a week01 subdirectory of your class directory
          % mkdir week01        # do this from your cs21/class subdirectory
          % cd  week01
          % pwd
    	
  3. open a new file named hellothere.py in vim and type in the following python code (indentation is important), save and exit vim (:wq):
      def main():
    	   
          print "hello there!"
    
      main()
    
  4. at the Unix prompt run the python interpreter on your program and you should see it print the message "hello there!" to the terminal:
      % python hellothere.py
        hello there!
      %
    
    you can also run this program on the python interpreter in interactive mode:
      # runs hellothere.py in interactive mode:
      % python -i hellothere.py
      >>>
    
    >>> is the python interpreter prompt, at this prompt you can enter other python code that the interpreter will interpret:
      >>> print "hello, who are you?"
    
    To exit the python interpreter hold down the control and the D keys together (CNTL-D)

    you can also just start the python interpreter in interactive mode without giving it a python code file to run:

      % python
      >>>