CS 100 - Computer Literacy, Fall 2004

Lab 8

This lab assignment will have you start JES and write a simple jython program.

Jython Environment for Students

The program Jython Environment for Students (or JES) is the development environment that we will use for the second part of this course. In the ACCC Labs, JES can be found by:
  1. Click on Start
  2. Then click on All Programs
  3. Then click on Class Applications
  4. Then click on Engineering
  5. Finally click on Jython Environment for Students

Jython is an implementation of the python language written in the java programming language. So the real name of the programming language we are using is python.

Once JES starts, it has two primary areas. The top area is the program area. The bottom area is the command area. The program area is really an editor that allows us to create, modify and save functions. The command area is similar to the UNIX prompt in which we can execute commands. In UNIX when we started the editor pico, we could use the prompt until we exited the editor. We could only display and use either the prompt or the editor, but never both at once. In JES, we have both the editor and prompt available to us at the same time.

Creating Functions in JES

The syntax to create a function in JES we use the def command. We type this in the program area so we can save the function to a file so we can use it again later. On the same line as the def, we type in three things:
  1. a name - this will be the name that we will use from the command area in JES to execute the function.
  2. an input list - this input list must be enclosed in parantheses. The input list is normally called the parameters of the function. This input list can be empty, contain a single parameter item or contain multiple parameter items separated by commas.
  3. a colon - this ends the line with the def command.
Following the line with the def command will be the body of the function. The body contains the commands the function will preform when executed. Indentation is used to separate one function from another and the different sections within a function. Paying careful attention to indentation is VERY VERY important.

We can use the File menu to select the menu items of Open, Save, Save As... and Load to perform tasks with the program area.

The print Command

The primary command we will use for this lab is the print command. The print command will cause information to be displayed in the command area. The print command can be given in the command area or as a command in a function. We can display either numbers or strings using the print command. A string is a sequence of characters enclosed in double quotes. The string will not show the double quotes when displayed. When displaying a number, we can list the number itself or an arithmetic expression. Below we will show the print command being used in command area. The prompt in the command area is three greater than signs. Information typed in will be displayed in bold text. The results will be displayed in normal text.

>>> print 5
5
>>> print 5 + 7
12
>>> print 7 - 5
-2
>>> print "Welcome"
Welcome
>>> print "Hello There"
Hello There
>>>

The print command is used in a similar way inside of a function. For example, assume we want a function to display two lines of text: first "Hello there." and then "How are you?". The function would be written as follows:

def hello():
  print "Hello there."
  print "How are you?"

The above function should be Saved and Loaded. When saving a function, by convention we use the file extension of .py with the filename. This helps identify that the file contains python function(s). Then we can execute the function by given the following command in the command area:

>>> hello()
Hello there.
How are you?
>>>

Lab Assignment 8

Due: Friday 10/23/2004 by 8:00 am

Create a python function using JES that will

  1. display a title of CS 100 Lab 8
  2. display your name
  3. display your Net-ID
  4. display your Time of Lab

This function is to be saved to a file and load so it can be executed in the command area of JES.

On the ACCC lab computers, the H: drive is a permanent storage area for you. Saving files to this drive on one computer can be accessed from another computer (even another computer in a different lab). It is suggested that you save your python programs to the H: drive.

Use the UNIX turnin command to electronically hand-in your python file using the project name of lab8. Note: you will need to transfer your python file to your icarus account before you can use turnin. You can do this by using the file transfer function of SSH or by emailing your python file to your incarus account. To submit the file in <filename>.py for lab8, the turnin command is entered as:

     turnin -c troy -p lab8 <filename>.py