Compsci 101, Fall 2015, Lab 1

Getting Credit for Lab 1

In each lab for Compsci 101 there will be a form to complete to earn credit for the lab.

To get credit for lab 1, you will need to enter your names and netids, and the answers to several questions on an online form.

Fill out this form for credit for Lab 1

Here are the questions to answer for this lab, these are duplicated in the form.

Getting Started Programming

Before coming to lab you should have attempted to install the software you need for this course here: software install instructions

In this lab

If you have any questions about the course, post your questions to Piazza the course discussion forum. If you are not on you'll need to sign up for an account for CompSci 101 Fall 2015 using your Duke email address.

PART 1: Install Python and related software

To write programs, you will need some software tools, just as writing a paper requires a wordprocessor (pretty much), writing software requires using 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.

Click here to for software install instructions If you don't get this done in lab, find a UTA in the LINK or see one of the course instructors during office hours to get this done.

PART 2: Snarfing and Running a Python program

"Snarfing" a program is just our cool way of creating a program that you will download or copy to your computer. By snarfing this complete python program, it will already be ready to run and you can then modify it to see how you can change it.

  1. You should start Eclipse and create a workspace for all your CompSci work (like compsci101) if you have not already. You can put your workspace anywhere, but you will need to remember where it is later in the semester.
  2. 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:
  3. http://www.cs.duke.edu/courses/compsci101/fall15/snarf
  4. Once the project fall15_cps101_lab01 has been created you are ready to test your installation and experiment with Python code.
  5. If you have trouble with snarf, you can also get the file graphing.py here.

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!

You should see a graph that looks like the picture below.

picture

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 enter your answers in the online form.

  1. Currently, the program plots the expression y = 3*x2 - 7x + 20 over the range, x-values, [0, 10]. Change the program so it graphs the same expression but instead between the x-values 0 and 20. This will require finding the part of the program that calls the function displayFunctionGraph and changing the first two parameters of the call.
  2. Change the program to plot the expression y = (x-4)3 over the range [0, 20].

    This will require changing the body of the function named functionToGraph. Note that to raise to a power use the ** operator, e.g., 2**5 is Python for 25.

  3. Change the program to plot a graph of y = sin(x) over the range [0,20]. To use the sin function you'll need to write math.sin(x) because sin is in the math library. How many complete cycles of the sine wave are there between 0 and 20 according to what you see?
  4. Graph a function where the y-value is chosen at random by changing the body of functionToGraph to the following:
        return random.randint(0,20)
    
    What do you see and why? Note this on the online form.

PART 3: Scratch Programming

Create a sample scratch program, upload it to the Scratch site enter the link to your scratch program in the online questionaire form.

  1. Start by going to the Scratch site .
  2. You should create an account if you haven't before and login to your account. You will need to do this so you can save and share your work.
  3. Click on the Create tab at the top of the browser and you are ready to start programming. There should be a "Getting Started with Scratch" tutorial that you can follow to build a sample scratch program. If you don't see it, you may need to click on a ? on the top right area of your browser, and then click on "Getting Started with Scratch" under the Step-by-step guides.
  4. Create a Scratch world following the steps in the guide and feel free to embellish it.
  5. When your program is finished, follow the share instructions to share your program.
  6. You'll need to cut and paste the URL of your program into the google form.


See above for how to get credit for this lab. You will need to answer questions in a google form.