CS 4950 Spring 2017
Find a computer and log into the
OSX side using your CS login name and password.
Open Firefox and find the class web
Open TextWrangler - use the finder
window and go to applications.
Open a new text file, called Lab4.txt, to record your work today -
you will paste in some of your command lines. The header of the file
should look like:
March 17, 2017
Find the Terminal - use the finder
window and go to applications and then utilities.
Introduction to Python
We are going to start out using the Python interpreter
In the terminal type Python to open then interpreter, then at the
prompt type the following and enter
>>> print "hello world"
For each command you run, copy the command line and the output into
your Lab4.txt file.
Create a list and a sum variable
L = [2,3,4,5,6]
>>> sum = 0
Now add all of the elements in the list (you will need to hit enter
to get back to the prompt after sum = sum + i)
for i in L:
sum = sum + i
Use the built-in function len() to get the length - number of
elements in the list L
Use a simple if statement to check for an element in L
if 3 in L:
print 'found it'
Now try out the arithmetic operators to do some computations and
make some notes about what you observe
Now work through the examples starting on page 128 in the
interpreter (not as a script yet).
"math.sqrt(100) : ", math.sqrt(100)
You can exit the interpreter by typing ^d (control d).
If you get to the end, put it in a script and try to run it.
Even if it is not in your script directory you can always run it
from the directory where it is saved by typing:
where myscript.py is the name of your file.
Turn it in:
Go to the CS Homework Submission System: https://www.cs.csustan.edu/cshomework/
Choose: instructor Martin
Upload the your Lab5.txt file as prompted.