CS 100 - Computer Literacy, Spring 2005
Lab 2
This lab assignment will have you start JES and
write a simple jython program.
Creation of your Icarus account
During the course of the semester, you will need to use your
account on Icarus which is UIC's UNIX machine. To create an
account on Icarus, visit the
ACCC's Accounts, Machines and Passwords Page. Follow
the link "Accounts - Open an ACCC Account Step 3" located
under the New Accounts heading.
The Icarus account will be used to store any web pages you
wish to make available to the world via the World Wide Web.
We will cover some basic commands later in the semester
(if you are interested now, you check out the
ACCC's Basic UNIX web page).
You should log onto icarus using SSH which stands for
Secure SHell. The ACCC has some web page support
for
SSH. An alternative program to SSH is
PuTTY.
The added security of these programs is a level of encryption that
the traditional
telnet program lacks.
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 some of the ACCC Labs, JES can be found by:
- Click on Start
- Then click on All Programs
- Then click on Class Applications
- Then click on Engineering
- 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:
- a name - this will be the name that we will use from the command
area in JES to execute the function.
- 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.
- 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.
-
Open bring an existing file into the program area.
-
Save stores the function(s) in the program area to
a file.
-
Save As... stores the function(s) in the program area to
a file under a different name that is currently being used.
-
Load allows the changes made in the function(s) in the
program area to be accessed when specifying the function name
in the command 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 2
Due: Monday 1/31/2005 by 12:00 noon
Create a python function using JES that will
- display a title of CS 100 Lab 2
- display your name
- display your Net-ID
- 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.
You are to submit the file you saved your function in by
emailing it as an attachment to the CS 100 course account.
The email address of CS 100 course account is i100@cs.uic.edu.
Be sure to specify the subject of the email to be something
like: CS 100 Lab 2.