The purpose of this first lab is to familiarize you with the environment you will be using in this course. In particular, this lab will introduce you to the Linux operating system, HTML, and Python programming tools.
The computer workstations in our lab can run both Windows and Linux operating systems. We will use the Linux operating system in this course.
Note: Outside of lab, you may access your Linux account from any computer connected to the Internet, provided you have appropriate access software, e.g., a secure shell client program. Some work for this course you can do from any computer, but most work you will have to do directly on the Linux machines.
This lab is a "warm up" for the semester. We want to make sure that you are comfortable with the environment before you start to program.
After the lab, you should know how to
If you can do all those things, you are all set for the course!
For this part of the lab, work through the handout and do the exercises. Hand in the worksheet before you leave lab.
We will use the Sakai forums for submitting summaries for the "Broader Issues in Computer Science" part of the course.
We're going to create a web page using a simple text editor. Creating web pages isn't all that a computer scientist does. However, the Web is a great venue for a computer scientist to share her work with the world! (Or to create resources and information for her students.)
public_html
directory. This is
where you will put files that you want others to see on the Internet.example.css
,
example.html
, and
example.gif
files from
/home/courses/cs111/handouts/lab0
into your
public_html directory.
(Recall: what is the special name for the current directory?)
http://www.cs.wlu.edu/~yourusername/example.html
You
should see the example web page. If you get an error message in the
browser window, ask for help.
http://www.cs.wlu.edu/~yourusername/
example.html
into a file named
index.html
. Now, point your browser to the
location:
http://www.cs.wlu.edu/~yourusername/
(We can talk about what's going on here more later in the course, but for now, just realize that index.html hides the contents of your web directory.)
jedit index.html &
The "&
" (called the "ampersand") is a special
command to let the terminal know that you want the program to open in a new
window and let you keep using the terminal window too. I will also refer to
the ampersand as saying that you want the command to "run in the background".
jEdit is a "text editor", i.e., a program that helps you create files. jEdit looks similar to a Word Processor. Look through some of the menus and you'll notice a lot of functionality that you'd see in a typical Word Processor, such as save, open, copy, and paste.
<title>
and </title>
tags) and the top-level heading (between the <h1>
and </h1>
tags) say Your Name's Web Page instead of Example Web Page. Save the
file. Reload the page in the
browser.
Note that the page has several links to other online documents in it. The HTML Help link is useful if you want to develop more web pages after this brief introduction.
Note the pattern of the links in the HTML file. How would you create a link to CNN? (You will perform similar activities throughout the course. You'll look at example code that does something similar to what you want to do, copy the code, and modify the code to do what you want.)
img
) tag in your web page to display this image.
Note that you didn't need any fancy software to be able to create a nice web page! I create my web pages for the course in a similar manner.
In a terminal window, navigate to your directory for this lab, which
you set up earlier. (It should be in labs/lab0
.)
In general, on our system, you have two options for writing Python programs:
OR
For this part of the exercise and most of the course, use IDLE.
To open Python's integrated development environment IDLE,
use the command idle &
Recall: what does the & allow you to do?
You can use the shell to tryout expressions before putting
them into a script. To get the shell in the terminal, simply
type python
. In IDLE, the main window is the Python shell.
Type the following expressions at the shell prompt, one line at a time, and note what the shell returns:
Save the output from the shell in a file called
shell_practice.out
.
Make
sure that this file is saved in the appropriate directory
(labs/lab0
).
Open the file hello.py
, which you
copied earlier. What should the code do? Execute the script by
hitting F5 to verify your expectations.
Now, open the file practice.py
and
execute the program.
Save the output from the shell in a file called
practice.out
. Make sure that this file is
saved in the appropriate directory (labs/lab0
).
Your programs will be graded on both correctness and style. Style will become more important as the semester continues.
Note that the convention is that the names of Python scripts end in
".py
".
practice.py
into a file called
practice2.py
.
Modify the program in two ways:
Modify the comments at the top of the program appropriately.
After you are sure that your program works and you have saved your
program, start a new IDLE shell by closing the shell and starting a
new one. Execute your program to demonstrate that your program
works. Save the output from the shell in a file called
practice2.out
.
info.py
that
prints out information about yourself. The info printed should list your
name, favorite sports team (could be professional, college, or other),
favorite color, and favorite dwarf (Sleepy, Sneezy, Happy, Grumpy, Dopey,
Bashful, or Doc). Don't forget to document your program appropriately!
You will use four separate print statements on four separate lines to print this information.
The output should looks something like:
Example Output:
Name: Sara Sprenkle Favorite team: Duke Favorite color: purple Favorite dwarf: Doc
After you are sure that your program works and you have saved your
program, close the IDLE shell and re-excute the program. Save the
output from the shell in a file
called info.out
.
turnin
directory.
(Review the UNIX handout if you don't remember how to
do that.)
printLab.sh <labdirpath>
lab0
directory, it's
easiest to "go up a
level" to the parent directory and use the script.
Putting it all together, if you're in your labs
directory, the
command is
printLab.sh lab0
The script printLab.sh
creates a condensed version of your lab in a postscript file called
lab0.ps
. To save paper, the script puts two
pages on a piece
of paper. The script also highlights the Python code appropriately.
gv
lab0.ps
gv
is short for
"ghostview"
and allows you to view postscript files, which are suitable
for printing. Your file should not be more than a few pages.
Otherwise, you're printing too much. See the instructor or
student assistant if you're having trouble.
lpr
-P<printername> <filetoprint>
cslab
when you're in P405 or advlab
if you're in P413.
lpr
means to print the file. The
option 'P' says which printer to use (one of the CS lab printers), and the
argument says which file to print--in this case lab0.ps
.
For example, the command to print this lab, assuming that you're in
your labs
directory, is lpr -Pcslab lab0.ps
Turn in your printed lab assignment to the instructor.
Labs are due at the beginning of Friday's class. You should hand in the
printed copy at the beginning of class, and the electronic version should be
in the turnin
directory before 1:20 p.m. on
Friday.
Ask well before the deadline if you need help turning in your assignment!