Lab 0: Introduction to Linux and Python

Welcome

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.

Goals for Lab Zero

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

  1. log in and out of the Linux machines, and set up your account for this course
  2. access the Web on the Linux machines
  3. access the CS111 home page
  4. use the Sakai forums
  5. create a text file with a text editor
  6. write basic HTML files and display them online
  7. create a Python program, run it, create output files, print, and submit it

If you can do all those things, you are all set for the course!

Objective: Learning to Use the Linux Machines

For this part of the lab, work through the handout and do the exercises. Hand in the worksheet before you leave lab.

Objective: Using the Sakai Forums

We will use the Sakai forums for submitting summaries for the "Broader Issues in Computer Science" part of the course.

  1. Use your W&L username and password to log in to Sakai.
  2. Click on the "CSCI 111 W10" tab.
  3. Navigate to the "Forums" from the side menu bar or from the home page.
  4. Read over the existing entries/topics.

Objective: Using the Text Editor and Creating an HTML File

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.)

  1. Open a terminal using the shortcut icon you made earlier.
  2. Go into your public_html directory. This is where you will put files that you want others to see on the Internet.
  3. Copy the 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?)
  4. Open another tab in your browser so that you can switch between the lab instructions and your work. Point your browser at the location: 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.
  5. Point your browser at the location: http://www.cs.wlu.edu/~yourusername/
    What do you see?
  6. Copy example.html into a file named index.html. Now, point your browser to the location: http://www.cs.wlu.edu/~yourusername/
    What do you see?

    (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.)

  7. Type 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.

  8. Edit the file so that the title (between the <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.
    How cool is that?

    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.

  9. Add two more links to the page.
    1. The first link will be to some online article about computer science. See the Extra Credit page for ideas on how to find such an article. You may want to search for an article after lab, depending on your time constraints because we still have a lot to do in this lab.
    2. The second link will be to the CS111 student sitting to your right. If you're in the rightmost chair, you'll link to the leftmost person in the row behind you. If you're the back, rightmost person, you'll link to the leftmost person in the first row. Find out the person's full name and username to create the link. The text for the link should include the person's year, e.g, first-year, sophomore, too. We'll create a "ring" of CS111 students.

    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.)

  10. Next, add an image to your web page. Find an image from the web. Save the image into the appropriate directory. Change the image (img) tag in your web page to display this image.
  11. Don't forget to update the information at the bottom of the page as well, to give yourself credit for your work.

    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.

Objective: Introduction to Python Programming

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:

  1. write your programs in JEdit and use the terminal to run Python

    OR

  2. write your programs in IDLE, using its shell to run the programs and then restart the shell when you demonstrate your program working.

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).

Objective: Write your Own Programs

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".

Finishing up: What to turn in for this lab

  1. Turn in your UNIX worksheet to the instructor before leaving lab.
  2. Copy your lab0 directory into the turnin directory. (Review the UNIX handout if you don't remember how to do that.)
  3. Create a printable version of your lab assignment using the command:
    printLab.sh <labdirpath>
    In this case, your lab directory path is the path to "lab0". If you're currently in the 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.

  4. View your printout using the command 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.
  5. The syntax of the command to print the assignment is lpr -P<printername> <filetoprint>
    The printer name is cslab when you're in P405 or advlab if you're in P413.
    The command 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!

Grading (100 pts)