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
Before coming to lab you should have attempted to try out the VM we are using for this course. Instructions are here on the resource page.
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 2017 using your Duke email address. See the message on Sakai on how to sign up.
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 for Setting up Python on the VM If you don't get this done in lab, find a UTA during consulting hours or see one of the course instructors during office hours to get this done.
VERY IMPORTANT : It is important that you do not change the default workspace path in Eclipse that the VM gives you.
In setting up your environment, create a PyDev Project called SampleProject (you may have created this in the instructions on the Resource page).
Create a new Python program in this project called helloMessage that just prints any message you want to spread around, such as "Duke has a stellar team this year."
You will need to create a new PyDev Module that just prints that message.
Answer the following two questions
"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.
http://www.cs.duke.edu/courses/compsci101/fall17/snarf
fall17_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 =
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.
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.
What changes were needed to graph y=(x-4)3?
Describe in words what the curve that appears looks like.
[0,20]
.
To use the sin function you'll need to write
math.sin(x)
because sin is in the
math library.
functionToGraph
to the following:
return random.randint(0,20)
Create a sample scratch program, upload it to the Scratch site enter the link to your scratch program in the online questionaire form.
Specifically, answer these questions in the online form: