Lab Dates: Wednesday-Thursday, 29-30 August 2012

Today's lab will focus on using the Blackboard system and simple programs in python.
Software tools needed: web browser and python idle programming environment.

Using Blackboard

This course will use the on-line Blackboard system for submitting work electronically. Blackboard should be accessible through your CUNY portal account (http://portal.cuny.edu). If you have not used Blackboard in the past, information is available at the Computer Center (http://www.lehman.edu/itr/blackboard.php). They can set up your account and have information sheets about using the system.

After logging into the class webpage on Blackboard, go to Assignments and click on the link for the first laboratory exercise: Lab 1, Part 1. A short set of questions will appear on the screen. Answer the questions, and a grade will appear on the screen. You may repeat the problem set as many times as you wish before the end of the lab.

Timing Out: If the system times out and locks your attempt (happens rarely when the browser or PC crashes), send email to an instructor so they can clear the attempt so you can try again.

Using Python

We will be using the Idle programming environment for python. On the desktop, there is an Idle icon. Click the icon to launch idle. In the shell window that pops up, try typing some of the commands that we did in lecture (also from the textbook):

	print("Hello, world!")
	print()
	def greet(person):
	   print("Hello", person)
	greet("world")
(Indentation does matter, so, remember to indent the print line so that it is included in the greet() function.)

Next, let's write a program that will greet someone 5 times. Instead of using the shell window (which lets us try things immediately), lets use a text window, where we can save our program for later. The basic structure of the program will be:

#Define our function
	#Have a loop that repeats 5 times
	#Inside that loop, greet that person 
Copy the above lines into a new text window. Save, using the name, greetLoop.py to your USB drive. If you try to run your program, it will currently do nothing, since all the lines are proceeded by the `#' and treated as a comment.

Let's fill in a bit more of the program:

#Define our function
def greetLoop(person):
	#Have a loop that repeats 5 times
	#Inside that loop, greet that person 
	print("Hello", person)
Save your revised program and load it (using the menu). At the shell, if you type:
greetLoop("World")
how many times does the message get printed? Why?

Let's add in the missing loop, to make it print out the multiple times:

#Define our function
def greetLoop(person):
	#Have a loop that repeats 5 times
	for i in range(5):
	#Inside that loop, greet that person 
	print("Hello", person)
Save your revised program and load it (using the menu). At the shell, if you type:
greetLoop("World")
how many times does the message get printed? What went wrong? A loop only repeats statements indented below it. Since our print statement wasn't indented, it decided we had an `empty loop' followed by a simple print statement. To include the print statement in the loop, we add indentation:
#Define our function
def greetLoop(person):
	#Have a loop that repeats 5 times
	for i in range(5):
		#Inside that loop, greet that person 
		print("Hello", person)
Save your revised program and load it (using the menu). At the shell, if you type:
greetLoop("World")
how many times does the message get printed?

Change your program so the message is printed 25 times.

After completing your program, go to Labs tab in Blackboard and click on the link: Lab 1, Part 2. Use the file upload interface to upload your program. Remember to click the Submit button before closing the lab exercise.

With the remaining time, start Problem Set 1.