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.
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.
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.
"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.
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.http://www.cs.duke.edu/courses/compsci101/fall15/snarf
fall15_cps101_lab01
has been created you are ready to test your installation and experiment 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 enter your answers in the
online form.
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.
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.
[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?
functionToGraph
to the following:
return random.randint(0,20)What do you see and why? Note this on the online form.
Create a sample scratch program, upload it to the Scratch site enter the link to your scratch program in the online questionaire form.