Compsci 6/101, Fall 2011, Lab 1

Getting Up and Running with Python

This lab has two parts, one of which should be started before lab so that everyone is not trying to download the software at the same time.

  1. Install Python and the software we use to work with it. This will include running some programs to make sure Python is working for you.
  2. Working on algorithmic problem solving and thinking without a computer in groups of 3 to 4 students.

If you have any questions about the course, post your questions to Piazza, the course discussion forum. You will need to sign up for an account on Piazza using your Duke email address.

Turn in this page for your group

Install Python and related software

In order to write programs, you will need some other programs. These allow you to edit your program, translate it into a simpler representation that your computer can understand, and run it. These initial steps may seem a little overwhelming, but they only need to be done once to get things started and working together.

  1. Try to get Eclipse and Python installed before lab using the install pages as a guide. If not, we will to have flash drives during lab with the software for you to install.
  2. Start Eclipse and create a workspace for all your CompSci work (like compsci06spring11). You can put your workspace anywhere, but you will need to remember where it is later in the semester.
  3. Download (or "snarf") the project (code and related files) for Lab 1 through Eclipse and run it as discussed below.
    See this site for help with Snarfing. In general to snarf projects, click Browse Snarf Sites, then click Add a new project site. You should add this site:
  4. http://www.cs.duke.edu/courses/cps006/fall11/snarf
  5. Once the project 06fall11_lab01 has been created you are ready to test your installation and experiment with Python code.

Experimenting with Python Code

To run the code, open up the project file in src called graphing.py by double-clicking on it, then use the green Play button on the toolbar. You may have to choose what kind of Python run to use depending on your Python settings (choose Python Run if you have a choice). Running the program should create and display a graph. You may get a small rocket-shaped icon representing the open graph. If that worked, everything is installed correctly!

To experiment with the code, look at the file graphing.py, and try to figure out generally how it works. To direct your experimentation, do the problems below that require you to change the file graphing.py, run it to see the results, and write down your answers on the handin pages.

  1. Currently, the program plots the expression y = x2 - 7x + 20 over the range, x-values, [0, 5]. Change the program so it graphs the same expression but instead between the x-values 0 and 20.
  2. Change the program to plot the expression y = (x-4)3 over the range [0, 10].
  3. Change the program to plot the expression y = sin(x) over the range [0, 10]. To use the sin function you will need to write math.sin(x) instead of just sin is in the math library, not built directly into Python.
  4. Change the program to plot an expression where the y-value is chosen at random by changing functionToGraph to the following:
        return random.randint(0,20)