CSC111 Lab 3
Contents
Software Setup
Before you can use the JES programming environment, you need to install it first.
- Login to your Novell account.
- Open your H: drive in Windows Explorer.
- Open Windows Explorer a second time, so that you have two windows open.
- In the second window, enter this address in the Address bar: \\rescent\pc\COURSES\CSC\CSC111
- This is the place on the Novell network where you will find many files related to the homework assignments and the labs.
- Drag the folder named jes-3-1-1windows from the CSC111 window to your H: drive.
- Close the windows showing the CSC111 folder
- In the window showing your H: drive, open the JES folder and click on the JES icon (snake face with glasses :-)
- After a few (long) seconds, you should get the JES programming environment.
If you want to install JES on your personal computer
If you want to install JES on your Mac or Windows laptop or computer, you can get also get JES from the Web, at this address http://coweb.cc.gatech.edu/mediaComp-teach/26. Click on the the file jes-3-1-1-windows.zip if you use Windows, or on jes-3-1-1-macosx.dmg if you have a Mac, and install as you would a regular application.
Notes for Mac users
Jes for the Mac is available on Google code. Get Jes 3.2.1 for the Mac and install on your mac.
Lab Exercises
Open JES by double-clicking on the icon or navigating through the start menu (on pcs)
- In the window that opens, the top portion is program area, and the bottom portion is command area.
- You can enter Python commands directly into the command area. Note that they will be lost when you close JES.
- You can create functions and programs (also called recipes, in the text) to execute your commands, in the program area and save them with a filename ending in ‘.py’. You then can load these programs into the command area using the ‘Load’ button in the center-left of the JES window, and ‘call’ the functions to execute the commands you typed in and saved. You call a function (or recipe) by typing its name, with parentheses ‘()’ in the command window. We will do this below.
In the following exercises, you should type all the lines beginning with ‘>’ in the JES command window. Try to anticipate what response Python will give you once you type each command and press enter.
Command Area Exercises
Begin your lab exercises in the command area (the bottom part of the JES window). Type the following commands in this command area, and see what response you get from the Python interpreter.
> 2 + 3 > print 2 + 3
Now you will define a variable named ‘sum’ and then ask Python to display the value assigned to ‘sum’ by using a print statement
> sum = 2 + 3 > print sum
Below you will define a ‘character string’ (a list of characters), and then print out a statement using both the string “sum” and variable named sum. You will use print statements like the second one below very often as you learn to write more complicated programs and need to ‘debug’ them (i.e., find errors in what you have written)
> print "sum" > print "sum = ", sum
You can multiply both numbers and strings! Remember that to a computer everything is a symbol, and is ultimately reduced to 1s and 0s.
> print 4 * 5 > print sum * 5 > print "sum" * 5
Data types are a fundamental concept in computer programming, and something you use implicitly all the time when performing math on your own. For computer programming, you must always be very clear on what data type you are using. Above you used two different data types – integer and character string. Now you will use real numbers and see the difference in the result of a simple mathematical operation when you specify that Python must use integers versus real (or floating point) numbers. Do you get an unexpected result from either of these commands? Can you think of why this happened (this is discussed in the text)?
> print 2/3 > print 2.0/3.0
Note that only one of the numbers in your expression needs to be specified as a real number for Python to perform the operation as a floating point operation
> print 2.0/3
Finally, play with strings a little. In which of the examples below is the Python output of the print statement the same as the first “hello world” ?
> print "hello world" > print "hello", "world" > print "hello" + "world" > print "hello" + " world"
EXERCISE #1
Find a way to use dash to print a line of 60 dashes, such as this one:
|
EXERCISE #2
Find a way to use both variables and print a line of 60 characters, such as this one:
|
EXERCISE #3
and print 5 lines of 60 dashes using only the new variable line that you will have just created. |
Program Area Exercises
In the Program area, type in the following lines, being careful to follow the format exactly (including all punctuation and indenting)
def hello(): print "hello world"
def hello2(name): print "hello", name
Next, save these lines you have typed in a file named hello.py. You should save the file in a folder on your H: drive. Then load these commands into the command area by clicking on the ‘Load’ button in the center left of the JES window.
To see how your functions, or recipes, work, type the following lines in the control area. Note that some of these commands will give you error messages, rather than what you might expect as output from the recipes. What is different between the commands the produce the expected output and those that produce error messages?
> hello > hello() > hello2("Lucy") > hello2(Lucy) > sum = 2 + 3 > hello2("sum") > hello2(sum)
EXERCISE #4
|
Getting Ready for the Homework
To be sure you will be able to submit your homework, navigate to the homework folder now. This folder is a ‘dropbox’ on one of the Smith College computers. You can navigate to it as you did for installing JES at the start of the lab, or through the following path:
- My Network Place\Entire Network\NetWare Services\rescent\pc\COURSES\CSC\CSC111\Dropbox