In Class: Week 1, Wednesday and Friday
In your cs21 subdirectory create a directory named 'class' and cd into that
directory, and then make a directory named 'week01' and cd into that directory:
# cd into your cs21 subdirectory:
% cd
% cd cs21
% pwd
/home/your_user_name/cs21
% mkdir class
% cd class
% pwd
/home/your_user_name/cs21/class
% mkdir week01
% cd week01
% pwd
/home/your_user_name/cs21/class/week01
Now copy over all the files from my public/cs21/week01 directory into your
week01 directory (remember to add the dot as the destination of the cp command).
From your week01 directory:
% cp ~newhall/public/cs21/week01/* .
% ls
- We are going to start by looking at the firstProg.py program together,
so go ahead and open it in vim:
% vim firstProg.py
To run the program in the python interpreter:
% python firstProg.py
- Try modifying the firstProg.py in vim to print out a different string,
and run it.
- Next we will look at add.py. This program follows the general pattern
that all (most) programs follow:
- input phase: get data values for program variables
- compute phase: do something with the program's data (some operations on
variables and values)
- output phase: display the results to the user
Running Python Programs
You can run your python program in the python interpreter two different ways:
- Have the interpreter run your program to completion:
% python firstProg.py
- Run the interpreter in interactive mode on your program (the python
interpreter will continue to run after running your program, and you can
enter new python commands at the prompt >>>:
% python -i firstProg.py
>>>
>>> print "hello there"
hello there
>>>
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
>>>