Lab Dates: Wednesday-Thursday, 30-31 January 2013

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 Labs and click on the link for the first laboratory. Blow the title, click on the link for Lab 1. Follow the instructions that appear on the webpage.

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. Take the 5 question test about the lab. Remember to click the Submit button before closing the lab exercise. You may take the test as many times as you want until you get a perfect score.

With the remaining time, start Problem Set 1 (Problems 1-5).