mapping quake data

Lab 1
Programming for Data Analysis
Lehman College, City University of New York
Spring 2017

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.

We will be using Blackboard for in-class quizzes, submitting programs, and posting grades. Quizzes and submitting programs are done via the Content menu (left hand side of Home screen).

Chrome: There were known bugs using the previous version of Blackboard with the Chrome browser. In particular, the Chrome browser often would freeze during quizzes. These have reportedly been fixed in the new version.

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, since it is very simple and comes with all distributions of Python (if you would prefer to use another programming environment, both Spyder and Jupyter/iPython, are on the lab machines).

There are several ways to launch IDLE:

To see that it works, type at the prompt:
	print("Hello, world!")

Instead of using the shell window (which lets us try things immediately), let's use a text window, where we can save our program for later and submit it to Blackboard (this is the basis of the first program, due on Friday).

  1. First, open up a text window: on the menu bar, choose "File" and from that menu, choose "New File" (you can also type "⌘N").
  2. In that window, type:
    #Name:  ...your name here...
    #Date: February 3, 2017
    #This program prints: hello world
    
    print("Hello world")
    	
  3. Save the program (using the "Save" under the "File" menu or "⌘S"). When you save it, name it something that you will be remember for the future and end it in .py. For example, ps1.py. At the end of lab, save your programs to a USB drive, DropBox, or mail them to yourself.
  4. Run your program (using the "Run Module" from the "Run" menu or F5 key).
  5. If it prints "Hello World" to the screen, then log into Blackboard (see notes above). On the left hand menu, choose "Programming Problems". From the list, choose "Program #1". In the file upload, enter the name of the .py file you just created and ran, and click "Submit".

More Python: Turtles

Now that you have just submitted your first program, let's try some other Python commands:

  1. Open up a new file window in IDLE ("File > New File" or "⌘N").
  2. Type (or copy) into your window:
    import turtle
    tia = turtle.Turtle()
    for i in range(4):
        tia.forward(150)
        tia.right(90)
    
  3. Save your program ("File > Save" or "⌘S").
    Note: Choose a name for your file that is not turtle.py. When executing the "import turtle" statement, the computer first looks in the folder where the file is saved for the turtle module and then in the libraries (and other places on the path). So, it thinks the module is itself, causing all kinds of errors. To avoid this, name your program something like "myTurtle.py" or "program2.py".
  4. Run your program (using the "Run Module" from the "Run" menu or F5 key).
  5. Change your program so that it draws a hexagon (6-sided polygon).
  6. Test your program and modify until you have a hexagon. When you do, add comments at the top of your program:
    #Name:  ...your name here...
    #Date: February 3, 2017
    #This program draws a hexagon.
    	
    Run your program after editing to make sure you do not have any typos.
  7. Log into Blackboard (see notes above). On the left hand menu, choose "Programming Problems". From the list, choose "Program #2". In the file upload, enter the name of the .py file you just created and ran, and click "Submit".

A quick overview of the parts of your second program:

In-class Quiz

During lab, there is a quiz on the academic integrity policy of City University of New York. The password to access the quiz will be given during lab.

What's Next?

If you finish the lab early, now is a great time to get a head start on the programming problems due early next week. There's instructors to help you and you already have Python up and running. The Programming Problem List has problem descriptions, suggested reading, and due dates next to each problem.

Using Python on Your Computer

The Python programming language and IDLE environment are freely available for many platforms from python.org or Anaconda. For this class, we are using Python 3. Many features of the language (including the syntax of print statements) changed between the second and third version, so, you must use the Python 3 for submitting programs.