The first lab session is designed to get you acquainted with Python 2 and some basic programming. Python 2 is already installed on the lab machines (both in PHSC and Dale Hall), which run some version of Windows. There are different ways of interfacing with Python---the default way on Windows is to use Python's interpreter/editor called IDLE, which is what we will do in the lab. The default way on Mac/Un*x, where Python should already be installed (though your version may need to be updated) is from the command line (either running the interpreter or executing scripts). For assignments, you may interface with Python however you like.
Note: Python is sensitive to indentation when working with a block of multiple lines of code. Since the IDLE interpreter does automatic indentation, you may have difficulties doing a direct copy-paste into the IDLE interpreter window, even though copy-paste into the IDLE program window (or command line interpreter) may work. One issue is whether spaces are properly preserved in the source you copy from. (However, don't use copy-paste for this assignment, or you will learn nothing.)
Task 1: Go through One Day of IDLE Toying to get familiar with IDLE.
(At the part where he tells you to start playing around, you can
try a couple of examples from here, but don't spend more than 2
minutes on this.)
Note: the comma at the end of the code print i,
in this
tutorial
tells Python not to print a carriage return (newline), so everything will
be printed on the same line. If you instead use the code
print i
without the comma, all the numbers will appear on
different lines.
Task 2: Go through the Instant Hacking tutorial to get familiar with the basics
of programming and Python 2.
The last section (More Abstraction...) is not
too important for us, and you can skip it if you like.
The author of this page says not to type directly into the interpreter,
but it looks to me like everything works fine. You may either work directly
in the Interpreter window or in the Program window, whichever you prefer.
The tutorial is not designed for
interpreter mode, but I think you can use interpreter mode for almost,
if not, everything. Note: when defining functions, include an empty line
(hit enter/return again) to finish the function definition. Also, don't
waste minutes of lab time calling the sleep
function, as
appealing as that might be.
You may not finish this during the lab period, but you are expected to finish this on your own before next Friday. Also it will help for the...
Lab Homework 1 (due Fri Jan 24):
This assignment is meant to get us familiar with
lists and some basic linear algebra in Python.
(Clarification: for each exercise, use loops, e.g. a for or while loop,
to write your functions. E.g., don't just use range(1,n+1)
for the
first exercise.)
Further references: For various assignments, including possibly the above one, you may need to learn a little more Python on your own. The Official Python Tutorial is a good place to learn about the basics in more detail, though this assumes you are familiar with some programming terms and concepts. The Beginner's Guide has more references, including lists of Python intros for those with programming experience and those without (this is how I found the tutorial above). In particular, this WikiBook Tutorial for Non-programmers seems like a good tutorial, which is considerably more detailed than the one in Task 2. Last, when all else fails, you can just do a web search for "How do I do XXX in Python?"